IgnorePatterns.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // Directories
  30. "**/metadata/**",
  31. "**/metadata",
  32. "**/ps3_update/**",
  33. "**/ps3_update",
  34. "**/ps3_vprm/**",
  35. "**/ps3_vprm",
  36. "**/extrafanart/**",
  37. "**/extrafanart",
  38. "**/extrathumbs/**",
  39. "**/extrathumbs",
  40. "**/.actors/**",
  41. "**/.actors",
  42. "**/.wd_tv/**",
  43. "**/.wd_tv",
  44. "**/lost+found/**",
  45. "**/lost+found",
  46. // WMC temp recording directories that will constantly be written to
  47. "**/TempRec/**",
  48. "**/TempRec",
  49. "**/TempSBE/**",
  50. "**/TempSBE",
  51. // Synology
  52. "**/eaDir/**",
  53. "**/eaDir",
  54. "**/@eaDir/**",
  55. "**/@eaDir",
  56. "**/#recycle/**",
  57. "**/#recycle",
  58. // Qnap
  59. "**/@Recycle/**",
  60. "**/@Recycle",
  61. "**/.@__thumb/**",
  62. "**/.@__thumb",
  63. "**/$RECYCLE.BIN/**",
  64. "**/$RECYCLE.BIN",
  65. "**/System Volume Information/**",
  66. "**/System Volume Information",
  67. "**/.grab/**",
  68. "**/.grab",
  69. // Unix hidden files
  70. "**/.*",
  71. // Mac - if you ever remove the above.
  72. // "**/._*",
  73. // "**/.DS_Store",
  74. // thumbs.db
  75. "**/thumbs.db",
  76. // bts sync files
  77. "**/*.bts",
  78. "**/*.sync",
  79. };
  80. private static readonly GlobOptions _globOptions = new GlobOptions
  81. {
  82. Evaluation =
  83. {
  84. CaseInsensitive = true
  85. }
  86. };
  87. private static readonly Glob[] _globs = _patterns.Select(p => Glob.Parse(p, _globOptions)).ToArray();
  88. /// <summary>
  89. /// Returns true if the supplied path should be ignored.
  90. /// </summary>
  91. /// <param name="path">The path to test.</param>
  92. /// <returns>Whether to ignore the path.</returns>
  93. public static bool ShouldIgnore(ReadOnlySpan<char> path)
  94. {
  95. int len = _globs.Length;
  96. for (int i = 0; i < len; i++)
  97. {
  98. if (_globs[i].IsMatch(path))
  99. {
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. }
  106. }