2
0

IgnorePatterns.cs 3.4 KB

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