fix(app/download_processor): detect deleted files
This commit is contained in:
@@ -341,6 +341,16 @@ class DownloadProcessor (
|
||||
|
||||
if (task.status.isFinalStage()) {
|
||||
if (task.status != TaskStatus.SUCCESS) return@let
|
||||
// check if the media file has been deleted
|
||||
if (task.type == TaskType.DOWNLOAD) {
|
||||
val outputFile = runCatching {
|
||||
DocumentFile.fromTreeUri(remoteSideContext.androidContext, Uri.parse(task.extra))
|
||||
}.getOrNull()
|
||||
|
||||
if (outputFile != null && !outputFile.exists()) {
|
||||
return@let
|
||||
}
|
||||
}
|
||||
callbackOnFailure(translation["already_downloaded_toast"], null)
|
||||
} else {
|
||||
callbackOnFailure(translation["already_queued_toast"], null)
|
||||
|
||||
@@ -50,6 +50,13 @@ class TaskManager(
|
||||
return runBlocking {
|
||||
suspendCoroutine {
|
||||
queueExecutor.execute {
|
||||
taskDatabase.rawQuery("SELECT * FROM tasks WHERE hash = ?", arrayOf(task.hash)).use { cursor ->
|
||||
if (cursor.moveToNext()) {
|
||||
it.resumeWith(Result.success(cursor.getLong("id")))
|
||||
return@execute
|
||||
}
|
||||
}
|
||||
|
||||
val result = taskDatabase.insert("tasks", null, ContentValues().apply {
|
||||
put("type", task.type.key)
|
||||
put("hash", task.hash)
|
||||
@@ -57,6 +64,7 @@ class TaskManager(
|
||||
put("status", task.status.key)
|
||||
put("extra", task.extra)
|
||||
})
|
||||
|
||||
it.resumeWith(Result.success(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user