IgnorePatterns.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. "**/subs/**",
  49. "**/subs",
  50. // Trickplay files
  51. "**/*.trickplay",
  52. "**/*.trickplay/**",
  53. // WMC temp recording directories that will constantly be written to
  54. "**/TempRec/**",
  55. "**/TempRec",
  56. "**/TempSBE/**",
  57. "**/TempSBE",
  58. // Synology
  59. "**/eaDir/**",
  60. "**/eaDir",
  61. "**/@eaDir/**",
  62. "**/@eaDir",
  63. "**/#recycle/**",
  64. "**/#recycle",
  65. // Qnap
  66. "**/@Recycle/**",
  67. "**/@Recycle",
  68. "**/.@__thumb/**",
  69. "**/.@__thumb",
  70. "**/$RECYCLE.BIN/**",
  71. "**/$RECYCLE.BIN",
  72. "**/System Volume Information/**",
  73. "**/System Volume Information",
  74. "**/.grab/**",
  75. "**/.grab",
  76. // Unix hidden files
  77. "**/.*",
  78. // Mac - if you ever remove the above.
  79. // "**/._*",
  80. // "**/.DS_Store",
  81. // thumbs.db
  82. "**/thumbs.db",
  83. // bts sync files
  84. "**/*.bts",
  85. "**/*.sync",
  86. // zfs
  87. "**/.zfs/**",
  88. "**/.zfs"
  89. };
  90. private static readonly GlobOptions _globOptions = new GlobOptions
  91. {
  92. Evaluation =
  93. {
  94. CaseInsensitive = true
  95. }
  96. };
  97. private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions));
  98. /// <summary>
  99. /// Returns true if the supplied path should be ignored.
  100. /// </summary>
  101. /// <param name="path">The path to test.</param>
  102. /// <returns>Whether to ignore the path.</returns>
  103. public static bool ShouldIgnore(ReadOnlySpan<char> path)
  104. {
  105. int len = _globs.Length;
  106. for (int i = 0; i < len; i++)
  107. {
  108. if (_globs[i].IsMatch(path))
  109. {
  110. return true;
  111. }
  112. }
  113. return false;
  114. }
  115. }
  116. }