diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-10-02 22:48:08 +0200 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-10-02 22:48:08 +0200 |
| commit | d46109aa695ef7ba461c5db774e2a0577ab656b9 (patch) | |
| tree | ff7a8e863c795704e021725fadab8a7dc2e869c5 /tests/Jellyfin.Server.Implementations.Tests/Library | |
| parent | 02c2951eb72d7282ff9e1c7610489edb924898c3 (diff) | |
Confine ignore file handling to library root
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests/Library')
| -rw-r--r-- | tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs index 03c0b4af39..94de2f7b23 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs @@ -470,4 +470,105 @@ public class DotIgnoreIgnoreRuleTest Directory.Delete(tempDir, true); } } + + [Fact] + public void LibraryRoot_IgnoreFileAboveRoot_IsNotConsulted() + { + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + var libraryRoot = Path.Combine(tempDir, "Movies"); + var movieDir = Path.Combine(libraryRoot, "Movie (2020)"); + Directory.CreateDirectory(movieDir); + + try + { + File.WriteAllText(Path.Combine(tempDir, ".ignore"), string.Empty); + + var rule = new DotIgnoreIgnoreRule(); + var fileInfo = new FileSystemMetadata + { + FullName = Path.Combine(movieDir, "Movie (2020).mkv"), + IsDirectory = false + }; + + // Without library roots the walk reaches the filesystem root + Assert.True(rule.ShouldIgnore(fileInfo, null)); + + rule.SetLibraryRootsProvider(() => [libraryRoot + Path.DirectorySeparatorChar]); + Assert.False(rule.ShouldIgnore(fileInfo, null)); + + // A .ignore in the library root itself still applies + File.WriteAllText(Path.Combine(libraryRoot, ".ignore"), "*.mkv"); + rule.ClearDirectoryCache(); + Assert.True(rule.ShouldIgnore(fileInfo, null)); + } + finally + { + Directory.Delete(tempDir, true); + } + } + + [Fact] + public void LibraryRoot_NestedRoots_StopAtOutermost() + { + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + var outerRoot = Path.Combine(tempDir, "Media"); + var innerRoot = Path.Combine(outerRoot, "Movies"); + Directory.CreateDirectory(innerRoot); + + try + { + File.WriteAllText(Path.Combine(outerRoot, ".ignore"), "*.mkv"); + + var rule = new DotIgnoreIgnoreRule(); + rule.SetLibraryRootsProvider(() => [innerRoot, outerRoot]); + var fileInfo = new FileSystemMetadata + { + FullName = Path.Combine(innerRoot, "Movie.mkv"), + IsDirectory = false + }; + + Assert.True(rule.ShouldIgnore(fileInfo, null)); + } + finally + { + Directory.Delete(tempDir, true); + } + } + + [Fact] + public void LibraryRoot_PathOutsideLibraries_WalksToFilesystemRoot() + { + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + var libraryRoot = Path.Combine(tempDir, "Movies"); + var otherDir = Path.Combine(tempDir, "Other", "Sub"); + Directory.CreateDirectory(libraryRoot); + Directory.CreateDirectory(otherDir); + + try + { + File.WriteAllText(Path.Combine(tempDir, ".ignore"), string.Empty); + + var rule = new DotIgnoreIgnoreRule(); + rule.SetLibraryRootsProvider(() => [libraryRoot]); + + // A sibling whose name only shares the root's prefix is not inside the library + var fileInfo = new FileSystemMetadata + { + FullName = Path.Combine(tempDir, "MoviesExtra", "Movie.mkv"), + IsDirectory = false + }; + Assert.True(rule.ShouldIgnore(fileInfo, null)); + + fileInfo = new FileSystemMetadata + { + FullName = Path.Combine(otherDir, "Movie.mkv"), + IsDirectory = false + }; + Assert.True(rule.ShouldIgnore(fileInfo, null)); + } + finally + { + Directory.Delete(tempDir, true); + } + } } |
