musikr: fix broken cover cleanup

This commit is contained in:
Alexander Capehart 2024-12-27 15:49:02 -05:00
parent b05d668b5e
commit d964df4616
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 7 additions and 10 deletions

View file

@ -435,7 +435,7 @@ constructor(
// Old cover revisions may be lying around, even during a normal refresh due
// to really lucky cancellations. Clean those up now that it's impossible for
// the rest of the app to be using them.
covers.cleanup(newLibrary)
covers.cleanup(newLibrary.songs.mapNotNull { it.cover })
}
private suspend fun emitIndexingProgress(progress: IndexingProgress) {

View file

@ -23,7 +23,6 @@ import java.io.File
import java.util.UUID
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.oxycblt.musikr.Library
import org.oxycblt.musikr.cover.Cover
import org.oxycblt.musikr.cover.CoverFiles
import org.oxycblt.musikr.cover.CoverFormat
@ -48,8 +47,8 @@ class SiloedCovers(
override suspend fun write(data: ByteArray) = SiloedCover(silo, inner.write(data))
override suspend fun cleanup(assuming: Library) {
inner.cleanup(assuming)
override suspend fun cleanup(excluding: Collection<Cover>) {
inner.cleanup(excluding.filterIsInstance<SiloedCover>().map { it.innerCover })
// Destroy old revisions no longer being used.
withContext(Dispatchers.IO) {
@ -88,7 +87,7 @@ data class CoverSilo(val revision: UUID, val params: CoverParams) {
}
}
class SiloedCover(silo: CoverSilo, private val innerCover: Cover) : Cover by innerCover {
class SiloedCover(silo: CoverSilo, val innerCover: Cover) : Cover by innerCover {
private val innerId = SiloedCoverId(silo, innerCover.id)
override val id = innerId.toString()
}

View file

@ -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 }
}