aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiyush Rungta <piyush@rungta.dev>2025-07-28 06:52:12 +0530
committerGitHub <noreply@github.com>2025-07-27 19:22:12 -0600
commite86315128d3773bf3ee0e8f1157d6fc1831ba380 (patch)
tree0462a6e9716b49b7bbde953f5b21bbc4406ea957
parentdfab2fb6e264ca5db9da111d5302678fe67f78ae (diff)
Ignore directory if empty .ignore file is present (#14536)
-rw-r--r--Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs29
1 files changed, 23 insertions, 6 deletions
diff --git a/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs b/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs
index b0ed1de8d..401ca73b8 100644
--- a/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs
+++ b/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs
@@ -42,6 +42,19 @@ public class DotIgnoreIgnoreRule : IResolverIgnoreRule
/// <returns>True if the file should be ignored.</returns>
public static bool IsIgnored(FileSystemMetadata fileInfo, BaseItem? parent)
{
+ if (fileInfo.IsDirectory)
+ {
+ var dirIgnoreFile = FindIgnoreFile(new DirectoryInfo(fileInfo.FullName));
+ if (dirIgnoreFile is null)
+ {
+ return false;
+ }
+
+ // ignore the directory only if the .ignore file is empty
+ // evaluate individual files otherwise
+ return string.IsNullOrWhiteSpace(GetFileContent(dirIgnoreFile));
+ }
+
var parentDirPath = Path.GetDirectoryName(fileInfo.FullName);
if (string.IsNullOrEmpty(parentDirPath))
{
@@ -55,13 +68,9 @@ public class DotIgnoreIgnoreRule : IResolverIgnoreRule
return false;
}
- string ignoreFileString;
- using (var reader = ignoreFile.OpenText())
- {
- ignoreFileString = reader.ReadToEnd();
- }
+ string ignoreFileString = GetFileContent(ignoreFile);
- if (string.IsNullOrEmpty(ignoreFileString))
+ if (string.IsNullOrWhiteSpace(ignoreFileString))
{
// Ignore directory if we just have the file
return true;
@@ -74,4 +83,12 @@ public class DotIgnoreIgnoreRule : IResolverIgnoreRule
return ignore.IsIgnored(fileInfo.FullName);
}
+
+ private static string GetFileContent(FileInfo dirIgnoreFile)
+ {
+ using (var reader = dirIgnoreFile.OpenText())
+ {
+ return reader.ReadToEnd();
+ }
+ }
}