Skip to content

Commit 50e9620

Browse files
committed
fix(auto-upload): work policy
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent e406142 commit 50e9620

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ internal class BackgroundJobManagerImpl(
511511

512512
workManager.enqueueUniqueWork(
513513
JOB_IMMEDIATE_FILES_SYNC + "_" + syncedFolderID,
514-
ExistingWorkPolicy.APPEND,
514+
ExistingWorkPolicy.KEEP,
515515
request
516516
)
517517
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ import com.owncloud.android.operations.UploadFileOperation
4343
import com.owncloud.android.ui.activity.SettingsActivity
4444
import com.owncloud.android.utils.theme.ViewThemeUtils
4545
import kotlinx.coroutines.Dispatchers
46+
import kotlinx.coroutines.ensureActive
47+
import kotlinx.coroutines.isActive
4648
import kotlinx.coroutines.withContext
4749
import java.io.File
50+
import kotlin.coroutines.cancellation.CancellationException
4851

4952
@Suppress("LongParameterList", "TooManyFunctions", "TooGenericExceptionCaught")
5053
class AutoUploadWorker(
@@ -90,7 +93,7 @@ class AutoUploadWorker(
9093
val contentUris = inputData.getStringArray(CONTENT_URIS)
9194

9295
if (canExitEarly(contentUris, syncFolderId)) {
93-
return Result.retry()
96+
return Result.success()
9497
}
9598

9699
if (powerManagementService.isPowerSavingEnabled) {
@@ -106,6 +109,9 @@ class AutoUploadWorker(
106109

107110
Log_OC.d(TAG, "${syncedFolder.remotePath} completed")
108111
Result.success()
112+
} catch (e: CancellationException) {
113+
Log_OC.w(TAG, "⚠️ Job cancelled")
114+
throw e
109115
} catch (e: Exception) {
110116
Log_OC.e(TAG, "❌ failed: ${e.message}")
111117
Result.failure()
@@ -279,7 +285,7 @@ class AutoUploadWorker(
279285

280286
var lastId = 0
281287

282-
while (true) {
288+
while (isActive) {
283289
val filePathsWithIds = repository.getFilePathsWithIds(syncedFolder, lastId)
284290

285291
if (filePathsWithIds.isEmpty()) {
@@ -289,6 +295,8 @@ class AutoUploadWorker(
289295
Log_OC.d(TAG, "started, processing batch: lastId=$lastId, count=${filePathsWithIds.size}")
290296

291297
filePathsWithIds.forEachIndexed { batchIndex, (path, id) ->
298+
ensureActive()
299+
292300
val file = File(path)
293301
val localPath = file.absolutePath
294302
val remotePath = syncFolderHelper.getAutoUploadRemotePath(syncedFolder, file)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class FileSystemRepository(
9191
dao.markFileAsUploaded(localPath, syncedFolderIdStr)
9292
Log_OC.d(TAG, "Marked file as uploaded: $localPath for syncedFolderId=$syncedFolderIdStr")
9393
} catch (e: Exception) {
94-
Log_OC.e(TAG, "Error marking file as uploaded: ${e.message}", e)
94+
Log_OC.e(TAG, "markFileAsHandled(): ${e.message}", e)
9595
}
9696
}
9797

0 commit comments

Comments
 (0)