musikr: fix broken cover cleanup
This commit is contained in:
parent
b05d668b5e
commit
d964df4616
3 changed files with 7 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue