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

109 lines
2.8 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",
"**/*sample*",
// 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 and directories
"**/.*/**",
2020-06-26 17:04:35 +00:00
"**/.*",
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
}
}
}