| | 1 | | using System; |
| | 2 | | using DotNet.Globbing; |
| | 3 | |
|
| | 4 | | namespace Emby.Server.Implementations.Library |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Glob patterns for files to ignore. |
| | 8 | | /// </summary> |
| | 9 | | public static class IgnorePatterns |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Files matching these glob patterns will be ignored. |
| | 13 | | /// </summary> |
| 1 | 14 | | private static readonly string[] _patterns = |
| 1 | 15 | | { |
| 1 | 16 | | "**/small.jpg", |
| 1 | 17 | | "**/albumart.jpg", |
| 1 | 18 | |
|
| 1 | 19 | | // We have neither non-greedy matching or character group repetitions, working around that here. |
| 1 | 20 | | // https://github.com/dazinator/DotNet.Glob#patterns |
| 1 | 21 | | // .*/sample\..{1,5} |
| 1 | 22 | | "**/sample.?", |
| 1 | 23 | | "**/sample.??", |
| 1 | 24 | | "**/sample.???", // Matches sample.mkv |
| 1 | 25 | | "**/sample.????", // Matches sample.webm |
| 1 | 26 | | "**/sample.?????", |
| 1 | 27 | | "**/*.sample.?", |
| 1 | 28 | | "**/*.sample.??", |
| 1 | 29 | | "**/*.sample.???", |
| 1 | 30 | | "**/*.sample.????", |
| 1 | 31 | | "**/*.sample.?????", |
| 1 | 32 | | "**/sample/*", |
| 1 | 33 | |
|
| 1 | 34 | | // Directories |
| 1 | 35 | | "**/metadata/**", |
| 1 | 36 | | "**/metadata", |
| 1 | 37 | | "**/ps3_update/**", |
| 1 | 38 | | "**/ps3_update", |
| 1 | 39 | | "**/ps3_vprm/**", |
| 1 | 40 | | "**/ps3_vprm", |
| 1 | 41 | | "**/extrafanart/**", |
| 1 | 42 | | "**/extrafanart", |
| 1 | 43 | | "**/extrathumbs/**", |
| 1 | 44 | | "**/extrathumbs", |
| 1 | 45 | | "**/.actors/**", |
| 1 | 46 | | "**/.actors", |
| 1 | 47 | | "**/.wd_tv/**", |
| 1 | 48 | | "**/.wd_tv", |
| 1 | 49 | | "**/lost+found/**", |
| 1 | 50 | | "**/lost+found", |
| 1 | 51 | |
|
| 1 | 52 | | // Trickplay files |
| 1 | 53 | | "**/*.trickplay", |
| 1 | 54 | | "**/*.trickplay/**", |
| 1 | 55 | |
|
| 1 | 56 | | // WMC temp recording directories that will constantly be written to |
| 1 | 57 | | "**/TempRec/**", |
| 1 | 58 | | "**/TempRec", |
| 1 | 59 | | "**/TempSBE/**", |
| 1 | 60 | | "**/TempSBE", |
| 1 | 61 | |
|
| 1 | 62 | | // Synology |
| 1 | 63 | | "**/eaDir/**", |
| 1 | 64 | | "**/eaDir", |
| 1 | 65 | | "**/@eaDir/**", |
| 1 | 66 | | "**/@eaDir", |
| 1 | 67 | | "**/#recycle/**", |
| 1 | 68 | | "**/#recycle", |
| 1 | 69 | |
|
| 1 | 70 | | // Qnap |
| 1 | 71 | | "**/@Recycle/**", |
| 1 | 72 | | "**/@Recycle", |
| 1 | 73 | | "**/.@__thumb/**", |
| 1 | 74 | | "**/.@__thumb", |
| 1 | 75 | | "**/$RECYCLE.BIN/**", |
| 1 | 76 | | "**/$RECYCLE.BIN", |
| 1 | 77 | | "**/System Volume Information/**", |
| 1 | 78 | | "**/System Volume Information", |
| 1 | 79 | | "**/.grab/**", |
| 1 | 80 | | "**/.grab", |
| 1 | 81 | |
|
| 1 | 82 | | // Unix hidden files |
| 1 | 83 | | "**/.*", |
| 1 | 84 | |
|
| 1 | 85 | | // Mac - if you ever remove the above. |
| 1 | 86 | | // "**/._*", |
| 1 | 87 | | // "**/.DS_Store", |
| 1 | 88 | |
|
| 1 | 89 | | // thumbs.db |
| 1 | 90 | | "**/thumbs.db", |
| 1 | 91 | |
|
| 1 | 92 | | // bts sync files |
| 1 | 93 | | "**/*.bts", |
| 1 | 94 | | "**/*.sync", |
| 1 | 95 | |
|
| 1 | 96 | | // zfs |
| 1 | 97 | | "**/.zfs/**", |
| 1 | 98 | | "**/.zfs" |
| 1 | 99 | | }; |
| | 100 | |
|
| 1 | 101 | | private static readonly GlobOptions _globOptions = new GlobOptions |
| 1 | 102 | | { |
| 1 | 103 | | Evaluation = |
| 1 | 104 | | { |
| 1 | 105 | | CaseInsensitive = true |
| 1 | 106 | | } |
| 1 | 107 | | }; |
| | 108 | |
|
| 1 | 109 | | private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions)); |
| | 110 | |
|
| | 111 | | /// <summary> |
| | 112 | | /// Returns true if the supplied path should be ignored. |
| | 113 | | /// </summary> |
| | 114 | | /// <param name="path">The path to test.</param> |
| | 115 | | /// <returns>Whether to ignore the path.</returns> |
| | 116 | | public static bool ShouldIgnore(ReadOnlySpan<char> path) |
| | 117 | | { |
| 26 | 118 | | int len = _globs.Length; |
| 2160 | 119 | | for (int i = 0; i < len; i++) |
| | 120 | | { |
| 1072 | 121 | | if (_globs[i].IsMatch(path)) |
| | 122 | | { |
| 18 | 123 | | return true; |
| | 124 | | } |
| | 125 | | } |
| | 126 | |
|
| 8 | 127 | | return false; |
| | 128 | | } |
| | 129 | | } |
| | 130 | | } |