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
|
// 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
|
// to really lucky cancellations. Clean those up now that it's impossible for
|
||||||
// the rest of the app to be using them.
|
// 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) {
|
private suspend fun emitIndexingProgress(progress: IndexingProgress) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.io.File
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.oxycblt.musikr.Library
|
|
||||||
import org.oxycblt.musikr.cover.Cover
|
import org.oxycblt.musikr.cover.Cover
|
||||||
import org.oxycblt.musikr.cover.CoverFiles
|
import org.oxycblt.musikr.cover.CoverFiles
|
||||||
import org.oxycblt.musikr.cover.CoverFormat
|
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 write(data: ByteArray) = SiloedCover(silo, inner.write(data))
|
||||||
|
|
||||||
override suspend fun cleanup(assuming: Library) {
|
override suspend fun cleanup(excluding: Collection<Cover>) {
|
||||||
inner.cleanup(assuming)
|
inner.cleanup(excluding.filterIsInstance<SiloedCover>().map { it.innerCover })
|
||||||
|
|
||||||
// Destroy old revisions no longer being used.
|
// Destroy old revisions no longer being used.
|
||||||
withContext(Dispatchers.IO) {
|
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)
|
private val innerId = SiloedCoverId(silo, innerCover.id)
|
||||||
override val id = innerId.toString()
|
override val id = innerId.toString()
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
package org.oxycblt.musikr.cover
|
package org.oxycblt.musikr.cover
|
||||||
|
|
||||||
import org.oxycblt.musikr.Library
|
|
||||||
|
|
||||||
interface Covers {
|
interface Covers {
|
||||||
suspend fun obtain(id: String): ObtainResult
|
suspend fun obtain(id: String): ObtainResult
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ interface Covers {
|
||||||
interface MutableCovers : Covers {
|
interface MutableCovers : Covers {
|
||||||
suspend fun write(data: ByteArray): Cover
|
suspend fun write(data: ByteArray): Cover
|
||||||
|
|
||||||
suspend fun cleanup(assuming: Library)
|
suspend fun cleanup(excluding: Collection<Cover>)
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface ObtainResult {
|
sealed interface ObtainResult {
|
||||||
|
@ -64,8 +62,8 @@ private class FileCovers(
|
||||||
return FileCover(id, file)
|
return FileCover(id, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun cleanup(assuming: Library) {
|
override suspend fun cleanup(excluding: Collection<Cover>) {
|
||||||
val used = assuming.songs.mapNotNullTo(mutableSetOf()) { it.cover?.id?.let(::getFileName) }
|
val used = excluding.mapTo(mutableSetOf()) { getFileName(it.id) }
|
||||||
coverFiles.deleteWhere { it !in used }
|
coverFiles.deleteWhere { it !in used }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue