IgnorePatterns.cs 3.2 KB

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