Merge pull request #11204 from revam/fix-resolver-helper-init-values

Don't expect `BaseItem` to be a movie/video file.
This commit is contained in:
Bond-009 2024-06-27 09:45:56 +02:00 committed by GitHub
commit 79e9fe112c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 79 additions and 11 deletions

View File

@ -39,7 +39,7 @@ namespace Emby.Server.Implementations.Library
item.GetParents().Any(i => i.IsLocked);
// Make sure DateCreated and DateModified have values
var fileInfo = directoryService.GetFile(item.Path);
var fileInfo = directoryService.GetFileSystemEntry(item.Path);
if (fileInfo is null)
{
return false;

View File

@ -61,11 +61,23 @@ namespace MediaBrowser.Controller.Providers
}
public FileSystemMetadata? GetFile(string path)
{
var entry = GetFileSystemEntry(path);
return entry is not null && !entry.IsDirectory ? entry : null;
}
public FileSystemMetadata? GetDirectory(string path)
{
var entry = GetFileSystemEntry(path);
return entry is not null && entry.IsDirectory ? entry : null;
}
public FileSystemMetadata? GetFileSystemEntry(string path)
{
if (!_fileCache.TryGetValue(path, out var result))
{
var file = _fileSystem.GetFileInfo(path);
if (file.Exists)
var file = _fileSystem.GetFileSystemInfo(path);
if (file?.Exists ?? false)
{
result = file;
_fileCache.TryAdd(path, result);

View File

@ -15,6 +15,10 @@ namespace MediaBrowser.Controller.Providers
FileSystemMetadata? GetFile(string path);
FileSystemMetadata? GetDirectory(string path);
FileSystemMetadata? GetFileSystemEntry(string path);
IReadOnlyList<string> GetFilePaths(string path);
IReadOnlyList<string> GetFilePaths(string path, bool clearCache, bool sort = false);

View File

@ -79,6 +79,21 @@ namespace Jellyfin.Controller.Tests
Assert.Equal(_lowerCaseFileSystemMetadata.Where(f => !f.IsDirectory), lowerCaseResult);
}
[Fact]
public void GetDirectories_GivenPathsWithDifferentCasing_ReturnsCorrectDirectories()
{
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == UpperCasePath), false)).Returns(_upperCaseFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemEntries(It.Is<string>(x => x == LowerCasePath), false)).Returns(_lowerCaseFileSystemMetadata);
var directoryService = new DirectoryService(fileSystemMock.Object);
var upperCaseResult = directoryService.GetDirectories(UpperCasePath);
var lowerCaseResult = directoryService.GetDirectories(LowerCasePath);
Assert.Equal(_upperCaseFileSystemMetadata.Where(f => f.IsDirectory), upperCaseResult);
Assert.Equal(_lowerCaseFileSystemMetadata.Where(f => f.IsDirectory), lowerCaseResult);
}
[Fact]
public void GetFile_GivenFilePathsWithDifferentCasing_ReturnsCorrectFile()
{
@ -95,15 +110,52 @@ namespace Jellyfin.Controller.Tests
Exists = false
};
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock.Setup(f => f.GetFileInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
var directoryService = new DirectoryService(fileSystemMock.Object);
var lowerCaseResult = directoryService.GetFile(lowerCasePath);
var upperCaseResult = directoryService.GetFile(upperCasePath);
var lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
var lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
var upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
var upperCaseFileResult = directoryService.GetFile(upperCasePath);
Assert.Equal(lowerCaseFileSystemMetadata, lowerCaseResult);
Assert.Null(upperCaseResult);
Assert.Null(lowerCaseDirResult);
Assert.Equal(lowerCaseFileSystemMetadata, lowerCaseFileResult);
Assert.Null(upperCaseDirResult);
Assert.Null(upperCaseFileResult);
}
[Fact]
public void GetDirectory_GivenFilePathsWithDifferentCasing_ReturnsCorrectDirectory()
{
const string lowerCasePath = "/music/someartist/Lyrics";
var lowerCaseFileSystemMetadata = new FileSystemMetadata
{
FullName = lowerCasePath,
IsDirectory = true,
Exists = true
};
const string upperCasePath = "/music/SOMEARTIST/LYRICS";
var upperCaseFileSystemMetadata = new FileSystemMetadata
{
FullName = upperCasePath,
IsDirectory = true,
Exists = false
};
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == upperCasePath))).Returns(upperCaseFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == lowerCasePath))).Returns(lowerCaseFileSystemMetadata);
var directoryService = new DirectoryService(fileSystemMock.Object);
var lowerCaseDirResult = directoryService.GetDirectory(lowerCasePath);
var lowerCaseFileResult = directoryService.GetFile(lowerCasePath);
var upperCaseDirResult = directoryService.GetDirectory(upperCasePath);
var upperCaseFileResult = directoryService.GetFile(upperCasePath);
Assert.Equal(lowerCaseFileSystemMetadata, lowerCaseDirResult);
Assert.Null(lowerCaseFileResult);
Assert.Null(upperCaseDirResult);
Assert.Null(upperCaseFileResult);
}
[Fact]
@ -122,11 +174,11 @@ namespace Jellyfin.Controller.Tests
};
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock.Setup(f => f.GetFileInfo(It.Is<string>(x => x == path))).Returns(cachedFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(cachedFileSystemMetadata);
var directoryService = new DirectoryService(fileSystemMock.Object);
var result = directoryService.GetFile(path);
fileSystemMock.Setup(f => f.GetFileInfo(It.Is<string>(x => x == path))).Returns(newFileSystemMetadata);
fileSystemMock.Setup(f => f.GetFileSystemInfo(It.Is<string>(x => x == path))).Returns(newFileSystemMetadata);
var secondResult = directoryService.GetFile(path);
Assert.Equal(cachedFileSystemMetadata, result);