From 0cf8b376acb9bb59be93865c566735df39490d0d Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Sun, 24 Mar 2024 01:11:45 +0100 Subject: Don't expect `BaseItem` to be a movie/video file. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix is mainly so I can mass-add series _and_ movie entries using a `IMultiItemResolver` without having to resort to complicated logic using _both_ a `IItemResolver` and a `IMultiItemResolver` by splitting up what gets added where. I've also added three new interface methods to the `IDirectoryService`, one of which is used in the modified `ResolverHelper.SetInitialItemValues(…)` to get the file system entry info for the item regardless of which type the file system entry is. In my local testing so far I haven't found any issues introduced by this change. --- MediaBrowser.Controller/Providers/DirectoryService.cs | 14 +++++++++++++- MediaBrowser.Controller/Providers/IDirectoryService.cs | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index 56b07ebae7..5ab1e27987 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -61,10 +61,22 @@ namespace MediaBrowser.Controller.Providers } public FileSystemMetadata? GetFile(string path) + { + var entry = GetFileSystemEntry(path); + return entry != null && !entry.IsDirectory ? entry : null; + } + + public FileSystemMetadata? GetDirectory(string path) + { + var entry = GetFileSystemEntry(path); + return entry != null && entry.IsDirectory ? entry : null; + } + + public FileSystemMetadata? GetFileSystemEntry(string path) { if (!_fileCache.TryGetValue(path, out var result)) { - var file = _fileSystem.GetFileInfo(path); + var file = _fileSystem.GetFileSystemInfo(path); if (file.Exists) { result = file; diff --git a/MediaBrowser.Controller/Providers/IDirectoryService.cs b/MediaBrowser.Controller/Providers/IDirectoryService.cs index a3c06cde53..1babf73af8 100644 --- a/MediaBrowser.Controller/Providers/IDirectoryService.cs +++ b/MediaBrowser.Controller/Providers/IDirectoryService.cs @@ -15,6 +15,10 @@ namespace MediaBrowser.Controller.Providers FileSystemMetadata? GetFile(string path); + FileSystemMetadata? GetDirectory(string path); + + FileSystemMetadata? GetFileSystemEntry(string path); + IReadOnlyList GetFilePaths(string path); IReadOnlyList GetFilePaths(string path, bool clearCache, bool sort = false); -- cgit v1.2.3 From 7b17b5b488989f37108b6f6d07be68050f0eb5f0 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Sun, 24 Mar 2024 04:41:15 +0000 Subject: fix: add null check --- MediaBrowser.Controller/Providers/DirectoryService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index 5ab1e27987..55f198ea21 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -77,7 +77,7 @@ namespace MediaBrowser.Controller.Providers if (!_fileCache.TryGetValue(path, out var result)) { var file = _fileSystem.GetFileSystemInfo(path); - if (file.Exists) + if (file?.Exists ?? false) { result = file; _fileCache.TryAdd(path, result); -- cgit v1.2.3 From 9b7da736ed1363f01528d7dfd1b7daa15039fa94 Mon Sep 17 00:00:00 2001 From: Mikal S <7761729+revam@users.noreply.github.com> Date: Sat, 15 Jun 2024 18:00:53 +0200 Subject: Replace `!=` with `is not` Co-authored-by: Bond-009 --- MediaBrowser.Controller/Providers/DirectoryService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index 55f198ea21..474f09dc5e 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -63,13 +63,13 @@ namespace MediaBrowser.Controller.Providers public FileSystemMetadata? GetFile(string path) { var entry = GetFileSystemEntry(path); - return entry != null && !entry.IsDirectory ? entry : null; + return entry is not null && !entry.IsDirectory ? entry : null; } public FileSystemMetadata? GetDirectory(string path) { var entry = GetFileSystemEntry(path); - return entry != null && entry.IsDirectory ? entry : null; + return entry is not null && entry.IsDirectory ? entry : null; } public FileSystemMetadata? GetFileSystemEntry(string path) -- cgit v1.2.3