Propagates music artwork deletion failures and keeps stored records consistent

This commit is contained in:
BinaryAlley committed 2026-11-16 23:19:30 +02:00
1 parent ab32add68a
commit 40ee922c18
4 files changed
+61 -4

No files matched your search

@@ -292,6 +292,7 @@ internal sealed class MusicArtworkService : IMusicArtworkService
/// <summary>
/// Deletes the files directly contained in <paramref name="artworkDirectoryPath"/>, leaving the subdirectories, such as the album directories of an artist, untouched.
/// The deletion stops at the first file that cannot be deleted, returning its error, so that a locked or read-only file is never silently ignored.
/// </summary>
/// <param name="artworkDirectoryPath">The file system path of the directory whose files are deleted.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
@@ -313,7 +314,12 @@ internal sealed class MusicArtworkService : IMusicArtworkService
return getFilesResult.Errors;
foreach (FileSystemPathId filePathId in getFilesResult.Value)
_environmentContext.FileProviderService.DeleteFile(filePathId);
{
// The bulk path stops at the first failure, because the artwork enricher only observes the bulk result: reporting the failure lets it retry the owner instead of storing new artwork over a file that could not be cleared.
Result<Deleted> deleteFileResult = _environmentContext.FileProviderService.DeleteFile(filePathId);
if (deleteFileResult.IsFailure)
return deleteFileResult.Errors;
}
return Result.Deleted;
}
@@ -415,6 +415,18 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
if (deleteStoredArtworkResult.IsFailure)
{
_logger.LogWarning("Failed to clear the stored artwork files of the {OwnerType} '{OwnerDescription}'.", ownerType, ownerDescription);
// Some files may have been deleted before the failure, so the stored records are dropped and the owner is marked as failed,
// keeping it eligible for a retry without serving the paths of the files that no longer exist.
Result<Deleted> deleteFailedEntitiesResult = await unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(ownerType, ownerId, cancellationToken).ConfigureAwait(false);
if (deleteFailedEntitiesResult.IsFailure)
_logger.LogWarning("Failed to clear the stored artwork records of the {OwnerType} '{OwnerDescription}'.", ownerType, ownerDescription);
else
{
List<MusicArtworkEntity> failedArtworkEntities = [CreateArtworkEntity(ownerId, ownerType, ArtworkType.Cover, 0, null, 0, ArtworkStatus.Failed, null)];
await PersistArtworkAsync(unitOfWork, failedArtworkEntities, cancellationToken).ConfigureAwait(false);
}
DeleteTemporaryArtworks(resolution.Artworks.Select(resolvedArtwork => resolvedArtwork.Artwork));
return false;
}