Fixing a bug with multiples paths in a library

This commit is contained in:
Zoe Roux 2020-06-12 04:04:31 +02:00
parent f7d79386d3
commit f18de8810b

View File

@ -72,13 +72,13 @@ namespace Kyoo.Controllers
Console.WriteLine("Scan finished!"); Console.WriteLine("Scan finished!");
} }
private Task Scan(Library library, ICollection<Episode> episodes, CancellationToken cancellationToken) private async Task Scan(Library library, ICollection<Episode> episodes, CancellationToken cancellationToken)
{ {
Console.WriteLine($"Scanning library {library.Name} at {string.Join(", ", library.Paths)}."); Console.WriteLine($"Scanning library {library.Name} at {string.Join(", ", library.Paths)}.");
return Task.WhenAll(library.Paths.Select(async path => foreach (string path in library.Paths)
{ {
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
return Task.CompletedTask; return;
string[] files; string[] files;
try try
@ -87,23 +87,23 @@ namespace Kyoo.Controllers
} }
catch (DirectoryNotFoundException) catch (DirectoryNotFoundException)
{ {
await Console.Error.WriteLineAsync($"The library's directory {path} could not be found (library slug: {library.Slug})"); Console.Error.WriteLine($"The library's directory {path} could not be found (library slug: {library.Slug})");
return Task.CompletedTask; return;
} }
catch (PathTooLongException) catch (PathTooLongException)
{ {
await Console.Error.WriteLineAsync($"The library's directory {path} is too long for this system. (library slug: {library.Slug})"); Console.Error.WriteLine($"The library's directory {path} is too long for this system. (library slug: {library.Slug})");
return Task.CompletedTask; return;
} }
catch (ArgumentException) catch (ArgumentException)
{ {
await Console.Error.WriteLineAsync($"The library's directory {path} is invalid. (library slug: {library.Slug})"); Console.Error.WriteLine($"The library's directory {path} is invalid. (library slug: {library.Slug})");
return Task.CompletedTask; return;
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
await Console.Error.WriteLineAsync($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})"); Console.Error.WriteLine($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})");
return Task.CompletedTask; return;
} }
// return Task.WhenAll(files.Select(file => // return Task.WhenAll(files.Select(file =>
@ -114,9 +114,7 @@ namespace Kyoo.Controllers
string relativePath = file.Substring(path.Length); string relativePath = file.Substring(path.Length);
/*return*/ await RegisterFile(file, relativePath, library, cancellationToken); /*return*/ await RegisterFile(file, relativePath, library, cancellationToken);
}//)); }//));
}//));
return Task.CompletedTask;
}));
} }
private async Task RegisterFile(string path, string relativePath, Library library, CancellationToken token) private async Task RegisterFile(string path, string relativePath, Library library, CancellationToken token)