jellyfin/Emby.Server.Implementations/Library/IgnorePatterns.cs

126 lines
3.4 KiB
C#
Raw Normal View History

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