2
0

IgnorePatterns.cs 3.5 KB

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