2
0

IgnorePatterns.cs 2.8 KB

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