From 6a1edfb9afcab64a791e2197286de03b968c7e78 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Mon, 25 Sep 2023 21:44:57 +0200 Subject: [PATCH] fix: catch directory not existing --- Shokofin/LibraryScanner.cs | 26 ++++++++++++++------------ Shokofin/Providers/SeriesProvider.cs | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Shokofin/LibraryScanner.cs b/Shokofin/LibraryScanner.cs index c246c68f..42ff18a4 100644 --- a/Shokofin/LibraryScanner.cs +++ b/Shokofin/LibraryScanner.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Linq; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -8,8 +9,6 @@ using Shokofin.API.Models; using Shokofin.Utils; -using Path = System.IO.Path; - namespace Shokofin { public class LibraryScanner : IResolverIgnoreRule @@ -92,18 +91,21 @@ private bool ScanDirectory(string partialPath, string fullPath, string libraryTy if (season == null) { // If we're in strict mode, then check the sub-directories if we have a // structure. if (shouldIgnore && partialPath[1..].Split(Path.DirectorySeparatorChar).Length == 1) { - var entries = FileSystem.GetDirectories(fullPath, false).ToList(); - Logger.LogDebug("Unable to find shoko series for {Path}, trying {DirCount} sub-directories.", entries.Count, partialPath); - foreach (var entry in entries) { - season = ApiManager.GetSeasonInfoByPath(entry.FullName) - .GetAwaiter() - .GetResult(); - if (season != null) - { - Logger.LogDebug("Found shoko series {SeriesName} for sub-directory of path {Path} (Series={SeriesId})", season.Shoko.Name, partialPath, season.Id); - break; + try { + var entries = FileSystem.GetDirectories(fullPath, false).ToList(); + Logger.LogDebug("Unable to find shoko series for {Path}, trying {DirCount} sub-directories.", partialPath, entries.Count); + foreach (var entry in entries) { + season = ApiManager.GetSeasonInfoByPath(entry.FullName) + .GetAwaiter() + .GetResult(); + if (season != null) + { + Logger.LogDebug("Found shoko series {SeriesName} for sub-directory of path {Path} (Series={SeriesId})", season.Shoko.Name, partialPath, season.Id); + break; + } } } + catch (DirectoryNotFoundException) { } } if (season == null) { if (shouldIgnore) diff --git a/Shokofin/Providers/SeriesProvider.cs b/Shokofin/Providers/SeriesProvider.cs index d258fab6..b93f1e45 100644 --- a/Shokofin/Providers/SeriesProvider.cs +++ b/Shokofin/Providers/SeriesProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net.Http; using System.Threading; @@ -42,15 +43,20 @@ public async Task> GetMetadata(SeriesInfo info, Cancellat var filterLibrary = Plugin.Instance.Configuration.FilterOnLibraryTypes ? Ordering.GroupFilterType.Others : Ordering.GroupFilterType.Default; var show = await ApiManager.GetShowInfoByPath(info.Path, filterLibrary); if (show == null) { - // Look for the "season" directories to probe for the group information - var entries = FileSystem.GetDirectories(info.Path, false); - foreach (var entry in entries) { - show = await ApiManager.GetShowInfoByPath(entry.FullName, filterLibrary); - if (show != null) - break; + try { + // Look for the "season" directories to probe for the group information + var entries = FileSystem.GetDirectories(info.Path, false); + foreach (var entry in entries) { + show = await ApiManager.GetShowInfoByPath(entry.FullName, filterLibrary); + if (show != null) + break; + } + if (show == null) { + Logger.LogWarning("Unable to find show info for path {Path}", info.Path); + return result; + } } - if (show == null) { - Logger.LogWarning("Unable to find show info for path {Path}", info.Path); + catch (DirectoryNotFoundException) { return result; } }