Browse Source

don't delete channel watermarks that are still used (#2781)

* don't delete channel watermarks that are still used

* fix folder cleanup check
pull/2783/head
Jason Dove 7 months ago committed by GitHub
parent
commit
3f4c9e063b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      ErsatzTV.Application/Maintenance/Commands/DeleteOrphanedArtworkHandler.cs

21
ErsatzTV.Application/Maintenance/Commands/DeleteOrphanedArtworkHandler.cs

@ -49,6 +49,17 @@ public class DeleteOrphanedArtworkHandler(
System.Collections.Generic.HashSet<string> validFiles = []; System.Collections.Generic.HashSet<string> validFiles = [];
List<string> watermarks = await dbContext.ChannelWatermarks
.TagWithCallSite()
.AsNoTracking()
.Select(c => c.Image)
.ToListAsync(cancellationToken);
foreach (string watermark in watermarks.Where(w => !string.IsNullOrWhiteSpace(w)))
{
validFiles.Add(watermark);
}
var lastId = 0; var lastId = 0;
while (true) while (true)
{ {
@ -142,7 +153,15 @@ public class DeleteOrphanedArtworkHandler(
{ {
try try
{ {
fileSystem.Directory.Delete(path); // don't delete artwork cache folder or its direct children
if (path != FileSystemLayout.ArtworkCacheFolder)
{
var parent = fileSystem.Directory.GetParent(path);
if (parent?.FullName != FileSystemLayout.ArtworkCacheFolder)
{
fileSystem.Directory.Delete(path);
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save