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

128 lines
3.4 KiB
C#
Raw Normal View History

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