aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Server.Implementations.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Jellyfin.Server.Implementations.Tests')
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/DotIgnoreIgnoreRuleTest.cs101
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/LibraryRootIgnoreTests.cs93
2 files changed, 194 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);
+ }
+ }
}
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/LibraryRootIgnoreTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/LibraryRootIgnoreTests.cs
new file mode 100644
index 0000000000..f37aadbe8d
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/LibraryRootIgnoreTests.cs
@@ -0,0 +1,93 @@
+using System;
+using System.IO;
+using AutoFixture;
+using AutoFixture.AutoMoq;
+using Emby.Naming.Common;
+using Emby.Server.Implementations.IO;
+using Emby.Server.Implementations.Library;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.IO;
+using Microsoft.Extensions.Logging.Abstractions;
+using Moq;
+using Xunit;
+
+namespace Jellyfin.Server.Implementations.Tests.Library.LibraryManager;
+
+public sealed class LibraryRootIgnoreTests : IDisposable
+{
+ private readonly string _tempDir;
+ private readonly string _userViewsPath;
+ private readonly string _libraryRoot;
+ private readonly FileSystemMetadata _movieFile;
+
+ public LibraryRootIgnoreTests()
+ {
+ _tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ _userViewsPath = Path.Combine(_tempDir, "root", "default");
+ _libraryRoot = Path.Combine(_tempDir, "media", "Movies");
+ var movieDir = Path.Combine(_libraryRoot, "Movie (2020)");
+ Directory.CreateDirectory(movieDir);
+
+ // Ignores everything below it, but sits above the library root
+ File.WriteAllText(Path.Combine(_tempDir, ".ignore"), string.Empty);
+
+ _movieFile = new FileSystemMetadata
+ {
+ FullName = Path.Combine(movieDir, "Movie (2020).mkv"),
+ IsDirectory = false
+ };
+ }
+
+ public void Dispose()
+ {
+ Directory.Delete(_tempDir, true);
+ }
+
+ [Fact]
+ public void IgnoreFile_IgnoreFileAboveMblinkLibraryRoot_IsNotConsulted()
+ {
+ var libraryDir = Path.Combine(_userViewsPath, "Movies");
+ Directory.CreateDirectory(libraryDir);
+ File.WriteAllText(Path.Combine(libraryDir, "Movies.mblink"), _libraryRoot);
+
+ Assert.False(CreateLibraryManager().IgnoreFile(_movieFile, null));
+ }
+
+ [Fact]
+ public void IgnoreFile_UserViewsPathMissing_WalksToFilesystemRoot()
+ {
+ // Before root/default exists there are no library roots, so the .ignore above still applies
+ Assert.False(Directory.Exists(_userViewsPath));
+ Assert.True(CreateLibraryManager().IgnoreFile(_movieFile, null));
+ }
+
+ private Emby.Server.Implementations.Library.LibraryManager CreateLibraryManager()
+ {
+ var fixture = new Fixture().Customize(new AutoMoqCustomization());
+ fixture.Register(() => new NamingOptions());
+ var configMock = fixture.Freeze<Mock<IServerConfigurationManager>>();
+ configMock.Setup(c => c.ApplicationPaths.ProgramDataPath).Returns(_tempDir);
+ configMock.Setup(c => c.ApplicationPaths.DefaultUserViewsPath).Returns(_userViewsPath);
+ fixture.Freeze<Mock<IServerApplicationHost>>()
+ .Setup(h => h.ExpandVirtualPath(It.IsAny<string>()))
+ .Returns<string>(path => path);
+ fixture.Inject<IFileSystem>(new ManagedFileSystem(
+ NullLogger<ManagedFileSystem>.Instance,
+ configMock.Object.ApplicationPaths,
+ [new MbLinkShortcutHandler()]));
+
+ // The same instance LibraryManager hands the roots to must be the one evaluating the rules
+ var dotIgnoreRule = new DotIgnoreIgnoreRule();
+ fixture.Inject(dotIgnoreRule);
+
+ return fixture.Build<Emby.Server.Implementations.Library.LibraryManager>().Do(s => s.AddParts(
+ [dotIgnoreRule],
+ [],
+ [],
+ Array.Empty<IBaseItemComparer>(),
+ []))
+ .Create();
+ }
+}