diff --git a/GSS2.Test/ProgramImagesStorageClear.cs b/GSS2.Test/ProgramImagesStorageClear.cs index 5b77388..cc80653 100644 --- a/GSS2.Test/ProgramImagesStorageClear.cs +++ b/GSS2.Test/ProgramImagesStorageClear.cs @@ -37,10 +37,12 @@ public partial class Program { _logger.LogInformation("Running images storage clear"); - var unusedFiles = _imageStorageService.ListFiles() + var recordsFiles = _context.ImageRecords.Select(r => r.ImagePath); + var storedFiles = _imageStorageService.ListFiles() .Select(Path.GetFileName) - .OfType() - .Where(f => !_context.ImageRecords.Any(r => r.ImagePath == f)); + .OfType(); + + var unusedFiles = storedFiles.Except(recordsFiles); if (unusedFiles is null || unusedFiles.Count() == 0) { @@ -51,7 +53,7 @@ public partial class Program _logger.LogInformation("Found {} unused image(s):\n\t{}", unusedFiles.Count(), string.Join("\n\t", unusedFiles)); - while (true) + while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Delete this files? (y/n) "); var input = Console.ReadLine()?.Trim();