Skip to content

Commit fe1f5f4

Browse files
alperozturk96backportbot[bot]
authored andcommitted
fix(auto-upload): remove not-existing local files without restarting
Signed-off-by: alperozturk <[email protected]> # Conflicts: # app/src/main/java/com/nextcloud/client/jobs/autoUpload/FileSystemRepository.kt
1 parent 13b0bad commit fe1f5f4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

app/src/main/java/com/nextcloud/client/database/dao/FileSystemDao.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ interface FileSystemDao {
1919
@Insert(onConflict = OnConflictStrategy.REPLACE)
2020
fun insertOrReplace(filesystemEntity: FilesystemEntity)
2121

22+
@Query(
23+
"""
24+
DELETE FROM ${ProviderMeta.ProviderTableMeta.FILESYSTEM_TABLE_NAME}
25+
WHERE ${ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH} = :localPath
26+
AND ${ProviderMeta.ProviderTableMeta._ID} = :id
27+
"""
28+
)
29+
suspend fun deleteByLocalPathAndId(
30+
localPath: String,
31+
id: Int
32+
)
33+
2234
@Query(
2335
"""
2436
SELECT *

app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ class AutoUploadWorker(
321321

322322
try {
323323
var (uploadEntity, upload) = createEntityAndUpload(user, localPath, remotePath)
324+
325+
// if local file deleted, upload cannot be or retriable thus needs to be removed
326+
if (path.isEmpty() || !file.exists()) {
327+
Log_OC.w(TAG, "detected not existing local file, removing entity")
328+
repository.deleteByLocalPathAndId(path, id)
329+
uploadsStorageManager.removeUpload(upload)
330+
continue
331+
}
332+
324333
try {
325334
// Insert/update to IN_PROGRESS state before starting upload
326335
val generatedId = uploadsStorageManager.uploadDao.insertOrReplace(uploadEntity)
@@ -366,10 +375,10 @@ class AutoUploadWorker(
366375
"Exception uploadFiles during creating entity and upload, localPath: $localPath, " +
367376
"remotePath: $remotePath, exception: $e"
368377
)
378+
} finally {
379+
// update last id so upload can continue where it left
380+
lastId = id
369381
}
370-
371-
// update last id so upload can continue where it left
372-
lastId = id
373382
}
374383
}
375384
}

0 commit comments

Comments
 (0)