2020-06-27 05:32:57 -04:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
using System;
|
2020-05-12 17:33:06 -04:00
|
|
|
using System.Linq;
|
|
|
|
using DotNet.Globbing;
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Library
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// Glob patterns for files to ignore.
|
2020-05-12 17:33:06 -04:00
|
|
|
/// </summary>
|
|
|
|
public static class IgnorePatterns
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// Files matching these glob patterns will be ignored.
|
2020-05-12 17:33:06 -04:00
|
|
|
/// </summary>
|
2020-06-26 13:04:35 -04:00
|
|
|
private static readonly string[] _patterns =
|
2020-05-12 17:33:06 -04:00
|
|
|
{
|
|
|
|
"**/small.jpg",
|
|
|
|
"**/albumart.jpg",
|
2020-07-25 17:50:49 -04:00
|
|
|
|
2020-07-26 17:02:11 -04:00
|
|
|
// We have neither non-greedy matching or character group repetitions, working around that here.
|
2020-07-26 11:11:43 -04:00
|
|
|
// https://github.com/dazinator/DotNet.Glob#patterns
|
2020-07-25 17:50:49 -04:00
|
|
|
"**/*.sample.?",
|
|
|
|
"**/*.sample.??",
|
2020-07-25 18:19:24 -04:00
|
|
|
"**/*.sample.???",
|
2020-07-25 17:50:49 -04:00
|
|
|
"**/*.sample.????",
|
|
|
|
"**/*.sample.?????",
|
|
|
|
"**/sample.?",
|
|
|
|
"**/sample.??",
|
2020-07-25 18:19:24 -04:00
|
|
|
"**/sample.???",
|
2020-07-25 17:50:49 -04:00
|
|
|
"**/sample.????",
|
|
|
|
"**/sample.?????",
|
|
|
|
"**/sample/*",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
|
|
|
// Directories
|
|
|
|
"**/metadata/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/metadata",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/ps3_update/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/ps3_update",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/ps3_vprm/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/ps3_vprm",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/extrafanart/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/extrafanart",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/extrathumbs/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/extrathumbs",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/.actors/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/.actors",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/.wd_tv/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/.wd_tv",
|
2020-05-19 21:45:48 -04:00
|
|
|
"**/lost+found/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/lost+found",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
|
|
|
// WMC temp recording directories that will constantly be written to
|
|
|
|
"**/TempRec/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/TempRec",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/TempSBE/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/TempSBE",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
|
|
|
// Synology
|
|
|
|
"**/eaDir/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/eaDir",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/@eaDir/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/@eaDir",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/#recycle/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/#recycle",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
|
|
|
// Qnap
|
|
|
|
"**/@Recycle/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/@Recycle",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/.@__thumb/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/.@__thumb",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/$RECYCLE.BIN/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/$RECYCLE.BIN",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/System Volume Information/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/System Volume Information",
|
2020-05-12 17:33:06 -04:00
|
|
|
"**/.grab/**",
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/.grab",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
2020-07-25 17:50:49 -04:00
|
|
|
// Unix hidden files
|
2020-06-26 13:04:35 -04:00
|
|
|
"**/.*",
|
2020-05-12 17:33:06 -04:00
|
|
|
|
2020-07-25 17:50:49 -04:00
|
|
|
// Mac - if you ever remove the above.
|
|
|
|
// "**/._*",
|
|
|
|
// "**/.DS_Store",
|
|
|
|
|
2020-05-12 17:33:06 -04:00
|
|
|
// thumbs.db
|
|
|
|
"**/thumbs.db",
|
|
|
|
|
|
|
|
// bts sync files
|
|
|
|
"**/*.bts",
|
|
|
|
"**/*.sync",
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly GlobOptions _globOptions = new GlobOptions
|
|
|
|
{
|
2020-06-26 13:04:35 -04:00
|
|
|
Evaluation =
|
|
|
|
{
|
2020-05-12 17:33:06 -04:00
|
|
|
CaseInsensitive = true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-26 13:04:35 -04:00
|
|
|
private static readonly Glob[] _globs = _patterns.Select(p => Glob.Parse(p, _globOptions)).ToArray();
|
2020-05-12 17:33:06 -04:00
|
|
|
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// Returns true if the supplied path should be ignored.
|
2020-05-12 17:33:06 -04:00
|
|
|
/// </summary>
|
2020-06-26 13:04:35 -04:00
|
|
|
/// <param name="path">The path to test.</param>
|
|
|
|
/// <returns>Whether to ignore the path.</returns>
|
2020-06-27 05:32:57 -04:00
|
|
|
public static bool ShouldIgnore(ReadOnlySpan<char> path)
|
2020-05-12 17:33:06 -04:00
|
|
|
{
|
2020-06-27 05:32:57 -04:00
|
|
|
int len = _globs.Length;
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (_globs[i].IsMatch(path))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-05-12 17:33:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|