musikr: fix broken cover cleanup

This commit is contained in:
Alexander Capehart
2024-12-27 15:49:26 -05:00
parent b05d668b5e
commit d964df4616
3 changed files with 7 additions and 10 deletions
@@ -18,8 +18,6 @@
package org.oxycblt.musikr.cover
import org.oxycblt.musikr.Library
interface Covers {
suspend fun obtain(id: String): ObtainResult
@@ -35,7 +33,7 @@ interface Covers {
interface MutableCovers : Covers {
suspend fun write(data: ByteArray): Cover
suspend fun cleanup(assuming: Library)
suspend fun cleanup(excluding: Collection<Cover>)
}
sealed interface ObtainResult {
@@ -64,8 +62,8 @@ private class FileCovers(
return FileCover(id, file)
}
override suspend fun cleanup(assuming: Library) {
val used = assuming.songs.mapNotNullTo(mutableSetOf()) { it.cover?.id?.let(::getFileName) }
override suspend fun cleanup(excluding: Collection<Cover>) {
val used = excluding.mapTo(mutableSetOf()) { getFileName(it.id) }
coverFiles.deleteWhere { it !in used }
}