IgnorePatterns.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Linq;
  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. "**/*sample*",
  18. // Directories
  19. "**/metadata/**",
  20. "**/metadata",
  21. "**/ps3_update/**",
  22. "**/ps3_update",
  23. "**/ps3_vprm/**",
  24. "**/ps3_vprm",
  25. "**/extrafanart/**",
  26. "**/extrafanart",
  27. "**/extrathumbs/**",
  28. "**/extrathumbs",
  29. "**/.actors/**",
  30. "**/.actors",
  31. "**/.wd_tv/**",
  32. "**/.wd_tv",
  33. "**/lost+found/**",
  34. "**/lost+found",
  35. // WMC temp recording directories that will constantly be written to
  36. "**/TempRec/**",
  37. "**/TempRec",
  38. "**/TempSBE/**",
  39. "**/TempSBE",
  40. // Synology
  41. "**/eaDir/**",
  42. "**/eaDir",
  43. "**/@eaDir/**",
  44. "**/@eaDir",
  45. "**/#recycle/**",
  46. "**/#recycle",
  47. // Qnap
  48. "**/@Recycle/**",
  49. "**/@Recycle",
  50. "**/.@__thumb/**",
  51. "**/.@__thumb",
  52. "**/$RECYCLE.BIN/**",
  53. "**/$RECYCLE.BIN",
  54. "**/System Volume Information/**",
  55. "**/System Volume Information",
  56. "**/.grab/**",
  57. "**/.grab",
  58. // Unix hidden files and directories
  59. "**/.*/**",
  60. "**/.*",
  61. // thumbs.db
  62. "**/thumbs.db",
  63. // bts sync files
  64. "**/*.bts",
  65. "**/*.sync",
  66. };
  67. private static readonly GlobOptions _globOptions = new GlobOptions
  68. {
  69. Evaluation =
  70. {
  71. CaseInsensitive = true
  72. }
  73. };
  74. private static readonly Glob[] _globs = _patterns.Select(p => Glob.Parse(p, _globOptions)).ToArray();
  75. /// <summary>
  76. /// Returns true if the supplied path should be ignored.
  77. /// </summary>
  78. /// <param name="path">The path to test.</param>
  79. /// <returns>Whether to ignore the path.</returns>
  80. public static bool ShouldIgnore(string path)
  81. {
  82. return _globs.Any(g => g.IsMatch(path));
  83. }
  84. }
  85. }