music: tweak revisioned cover api
This commit is contained in:
parent
0dc72b67af
commit
7b35ba840b
2 changed files with 10 additions and 10 deletions
|
@ -432,7 +432,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.
|
||||||
RevisionedCovers.cleanup(context, newRevision)
|
covers.cleanup(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun emitIndexingProgress(progress: IndexingProgress) {
|
private suspend fun emitIndexingProgress(progress: IndexingProgress) {
|
||||||
|
|
|
@ -41,6 +41,15 @@ class RevisionedCovers(private val revision: UUID, private val inner: MutableSto
|
||||||
return inner.write(data)?.let { RevisionedCover(revision, it) }
|
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 {
|
companion object {
|
||||||
suspend fun at(context: Context, revision: UUID): RevisionedCovers {
|
suspend fun at(context: Context, revision: UUID): RevisionedCovers {
|
||||||
val dir =
|
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))))
|
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>? {
|
private fun parse(id: String): Pair<String, UUID>? {
|
||||||
val split = id.split('@', limit = 2)
|
val split = id.split('@', limit = 2)
|
||||||
if (split.size != 2) return null
|
if (split.size != 2) return null
|
||||||
|
|
Loading…
Reference in a new issue