musikr: ignore stale folder covers

This commit is contained in:
Alexander Capehart 2025-03-03 15:10:46 -07:00
parent 4fbbbfdc76
commit b48bf3729e
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -37,9 +37,26 @@ open class FolderCovers(private val context: Context) : Covers<FolderCover> {
return CoverResult.Miss() return CoverResult.Miss()
} }
// TODO: Check if the dir actually exists still to avoid stale uris
val directoryUri = id.substring("folder:".length) val directoryUri = id.substring("folder:".length)
val uri = Uri.parse(directoryUri) val uri = Uri.parse(directoryUri)
return CoverResult.Hit(FolderCoverImpl(context, uri))
// Check if the URI is still valid
val exists =
withContext(Dispatchers.IO) {
try {
context.contentResolver.openFileDescriptor(uri, "r")?.close()
true
} catch (e: Exception) {
false
}
}
return if (exists) {
CoverResult.Hit(FolderCoverImpl(context, uri))
} else {
CoverResult.Miss()
}
} }
} }