music: tweak revisioned cover api

This commit is contained in:
Alexander Capehart 2024-12-27 09:51:18 -05:00
parent 0dc72b67af
commit 7b35ba840b
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 10 additions and 10 deletions

View file

@ -432,7 +432,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.
RevisionedCovers.cleanup(context, newRevision)
covers.cleanup(context)
}
private suspend fun emitIndexingProgress(progress: IndexingProgress) {

View file

@ -41,6 +41,15 @@ class RevisionedCovers(private val revision: UUID, private val inner: MutableSto
return inner.write(data)?.let { RevisionedCover(revision, it) }
}
suspend fun cleanup(context: Context) =
withContext(Dispatchers.IO) {
val exclude = revision.toString()
context.filesDir
.resolve("covers")
.listFiles { file -> file.name != exclude }
?.forEach { it.deleteRecursively() }
}
companion object {
suspend fun at(context: Context, revision: UUID): RevisionedCovers {
val dir =
@ -52,15 +61,6 @@ class RevisionedCovers(private val revision: UUID, private val inner: MutableSto
StoredCovers.from(CoverFiles.at(dir), CoverFormat.jpeg(CoverParams.of(750, 80))))
}
suspend fun cleanup(context: Context, exclude: UUID) =
withContext(Dispatchers.IO) {
val excludeName = exclude.toString()
context.filesDir
.resolve("covers")
.listFiles { file -> file.name != excludeName }
?.forEach { it.deleteRecursively() }
}
private fun parse(id: String): Pair<String, UUID>? {
val split = id.split('@', limit = 2)
if (split.size != 2) return null