IgnorePatterns.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using DotNet.Globbing;
  3. namespace Emby.Server.Implementations.Library
  4. {
  5. /// <summary>
  6. /// Glob patterns for files to ignore.
  7. /// </summary>
  8. public static class IgnorePatterns
  9. {
  10. /// <summary>
  11. /// Files matching these glob patterns will be ignored.
  12. /// </summary>
  13. private static readonly string[] _patterns =
  14. {
  15. "**/small.jpg",
  16. "**/albumart.jpg",
  17. // We have neither non-greedy matching or character group repetitions, working around that here.
  18. // https://github.com/dazinator/DotNet.Glob#patterns
  19. // .*/sample\..{1,5}
  20. "**/sample.?",
  21. "**/sample.??",
  22. "**/sample.???", // Matches sample.mkv
  23. "**/sample.????", // Matches sample.webm
  24. "**/sample.?????",
  25. "**/*.sample.?",
  26. "**/*.sample.??",
  27. "**/*.sample.???",
  28. "**/*.sample.????",
  29. "**/*.sample.?????",
  30. "**/sample/*",
  31. // Directories
  32. "**/metadata/**",
  33. "**/metadata",
  34. "**/ps3_update/**",
  35. "**/ps3_update",
  36. "**/ps3_vprm/**",
  37. "**/ps3_vprm",
  38. "**/extrafanart/**",
  39. "**/extrafanart",
  40. "**/extrathumbs/**",
  41. "**/extrathumbs",
  42. "**/.actors/**",
  43. "**/.actors",
  44. "**/.wd_tv/**",
  45. "**/.wd_tv",
  46. "**/lost+found/**",
  47. "**/lost+found",
  48. // Trickplay files
  49. "**/*.trickplay",
  50. "**/*.trickplay/**",
  51. // WMC temp recording directories that will constantly be written to
  52. "**/TempRec/**",
  53. "**/TempRec",
  54. "**/TempSBE/**",
  55. "**/TempSBE",
  56. // Synology
  57. "**/eaDir/**",
  58. "**/eaDir",
  59. "**/@eaDir/**",
  60. "**/@eaDir",
  61. "**/#recycle/**",
  62. "**/#recycle",
  63. // Qnap
  64. "**/@Recycle/**",
  65. "**/@Recycle",
  66. "**/.@__thumb/**",
  67. "**/.@__thumb",
  68. "**/$RECYCLE.BIN/**",
  69. "**/$RECYCLE.BIN",
  70. "**/System Volume Information/**",
  71. "**/System Volume Information",
  72. "**/.grab/**",
  73. "**/.grab",
  74. // Unix hidden files
  75. "**/.*",
  76. // Mac - if you ever remove the above.
  77. // "**/._*",
  78. // "**/.DS_Store",
  79. // thumbs.db
  80. "**/thumbs.db",
  81. // bts sync files
  82. "**/*.bts",
  83. "**/*.sync",
  84. // zfs
  85. "**/.zfs/**",
  86. "**/.zfs"
  87. };
  88. private static readonly GlobOptions _globOptions = new GlobOptions
  89. {
  90. Evaluation =
  91. {
  92. CaseInsensitive = true
  93. }
  94. };
  95. private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions));
  96. /// <summary>
  97. /// Returns true if the supplied path should be ignored.
  98. /// </summary>
  99. /// <param name="path">The path to test.</param>
  100. /// <returns>Whether to ignore the path.</returns>
  101. public static bool ShouldIgnore(ReadOnlySpan<char> path)
  102. {
  103. int len = _globs.Length;
  104. for (int i = 0; i < len; i++)
  105. {
  106. if (_globs[i].IsMatch(path))
  107. {
  108. return true;
  109. }
  110. }
  111. return false;
  112. }
  113. }
  114. }