IgnorePatterns.cs 3.4 KB

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