aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/IgnorePatterns.cs
blob: bb45dd87e97ea473918f3b00bf0f1d8be8988bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Linq;
using DotNet.Globbing;

namespace Emby.Server.Implementations.Library
{
    /// <summary>
    /// Glob patterns for files to ignore.
    /// </summary>
    public static class IgnorePatterns
    {
        /// <summary>
        /// Files matching these glob patterns will be ignored.
        /// </summary>
        private static readonly string[] _patterns =
        {
            "**/small.jpg",
            "**/albumart.jpg",

            // We have neither non-greedy matching or character group repetitions, working around that here.
            // https://github.com/dazinator/DotNet.Glob#patterns
            // .*/sample\..{1,5}
            "**/sample.?",
            "**/sample.??",
            "**/sample.???", // Matches sample.mkv
            "**/sample.????", // Matches sample.webm
            "**/sample.?????",
            "**/*.sample.?",
            "**/*.sample.??",
            "**/*.sample.???",
            "**/*.sample.????",
            "**/*.sample.?????",
            "**/sample/*",

            // Directories
            "**/metadata/**",
            "**/metadata",
            "**/ps3_update/**",
            "**/ps3_update",
            "**/ps3_vprm/**",
            "**/ps3_vprm",
            "**/extrafanart/**",
            "**/extrafanart",
            "**/extrathumbs/**",
            "**/extrathumbs",
            "**/.actors/**",
            "**/.actors",
            "**/.wd_tv/**",
            "**/.wd_tv",
            "**/lost+found/**",
            "**/lost+found",

            // Trickplay files
            "**/*.trickplay",
            "**/*.trickplay/**",

            // WMC temp recording directories that will constantly be written to
            "**/TempRec/**",
            "**/TempRec",
            "**/TempSBE/**",
            "**/TempSBE",

            // Synology
            "**/eaDir/**",
            "**/eaDir",
            "**/@eaDir/**",
            "**/@eaDir",
            "**/#recycle/**",
            "**/#recycle",

            // Qnap
            "**/@Recycle/**",
            "**/@Recycle",
            "**/.@__thumb/**",
            "**/.@__thumb",
            "**/$RECYCLE.BIN/**",
            "**/$RECYCLE.BIN",
            "**/System Volume Information/**",
            "**/System Volume Information",
            "**/.grab/**",
            "**/.grab",

            // Unix hidden files
            "**/.*",

            // Mac - if you ever remove the above.
            // "**/._*",
            // "**/.DS_Store",

            // thumbs.db
            "**/thumbs.db",

            // bts sync files
            "**/*.bts",
            "**/*.sync",

            // zfs
            "**/.zfs/**",
            "**/.zfs"
        };

        private static readonly GlobOptions _globOptions = new GlobOptions
        {
            Evaluation =
            {
                CaseInsensitive = true
            }
        };

        private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions));

        /// <summary>
        /// Returns true if the supplied path should be ignored.
        /// </summary>
        /// <param name="path">The path to test.</param>
        /// <returns>Whether to ignore the path.</returns>
        public static bool ShouldIgnore(ReadOnlySpan<char> path)
        {
            int len = _globs.Length;
            for (int i = 0; i < len; i++)
            {
                if (_globs[i].IsMatch(path))
                {
                    return true;
                }
            }

            return false;
        }
    }
}