From 602661db40328f5a75261175fa19a1b0567161b3 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 7 May 2020 05:12:41 +0200 Subject: [PATCH] Handling directory errors on library scan --- Kyoo/Tasks/Crawler.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index 73cb25b2..4f6b734d 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -79,14 +79,38 @@ namespace Kyoo.Controllers { if (cancellationToken.IsCancellationRequested) return; - - await Task.WhenAll(Directory.GetFiles(path, "*", SearchOption.AllDirectories).Select(file => + string[] files; + try + { + files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); + } + catch (DirectoryNotFoundException) + { + Console.Error.WriteLine($"The library's directory {path} could not be found (library slug: {library.Slug})"); + continue; + } + catch (PathTooLongException) + { + Console.Error.WriteLine($"The library's directory {path} is too long for this system. (library slug: {library.Slug})"); + continue; + } + catch (ArgumentException) + { + Console.Error.WriteLine($"The library's directory {path} is invalid. (library slug: {library.Slug})"); + continue; + } + catch (UnauthorizedAccessException) + { + Console.Error.WriteLine($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})"); + continue; + } + await Task.WhenAll(files.Select(file => { if (!IsVideo(file) || _libraryManager.GetEpisodes().Any(x => x.Path == file)) return null; string relativePath = file.Substring(path.Length); return RegisterFile(file, relativePath, library, cancellationToken); - })); + }).Where(x => x != null)); } }