[backend/drive] Report count of orphaned files removed by storage cleanup job on completion

This commit is contained in:
Laura Hausmann 2024-10-19 01:29:25 +02:00
parent ead9d90029
commit 79014ec4b7
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -258,6 +258,7 @@ public class StorageMaintenanceService(
.ToHashSet()); .ToHashSet());
logger.LogInformation("Loaded {count} files from database.", filenames.Count); logger.LogInformation("Loaded {count} files from database.", filenames.Count);
var count = 0;
if (options.Value.Local?.Path is { } path && Directory.Exists(path)) if (options.Value.Local?.Path is { } path && Directory.Exists(path))
{ {
@ -271,6 +272,7 @@ public class StorageMaintenanceService(
logger.LogInformation("Would delete {file} from disk, but --dry-run was specified.", file); logger.LogInformation("Would delete {file} from disk, but --dry-run was specified.", file);
else else
{ {
count++;
try try
{ {
File.Delete(file); File.Delete(file);
@ -295,6 +297,7 @@ public class StorageMaintenanceService(
logger.LogInformation("Would delete {file} from object storage, but --dry-run was specified.", key); logger.LogInformation("Would delete {file} from object storage, but --dry-run was specified.", key);
else else
{ {
count++;
try try
{ {
await objectStorageSvc.RemoveFilesAsync(key); await objectStorageSvc.RemoveFilesAsync(key);
@ -307,6 +310,6 @@ public class StorageMaintenanceService(
} }
} }
logger.LogInformation("Finished scanning for orphaned files."); logger.LogInformation("Finished removing {count} orphaned files.", count);
} }
} }