@@ -34,6 +34,7 @@ import com.owncloud.android.datamodel.SyncedFolder
3434import com.owncloud.android.datamodel.SyncedFolderProvider
3535import com.owncloud.android.datamodel.UploadsStorageManager
3636import com.owncloud.android.db.OCUpload
37+ import com.owncloud.android.db.UploadResult
3738import com.owncloud.android.lib.common.OwnCloudAccount
3839import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
3940import com.owncloud.android.lib.common.utils.Log_OC
@@ -302,7 +303,14 @@ class AutoUploadWorker(
302303 )
303304
304305 try {
305- var (uploadEntity, upload) = createEntityAndUpload(user, localPath, remotePath)
306+ val result = createEntityAndUpload(user, localPath, remotePath)
307+ if (result == null ) {
308+ repository.markFileAsHandled(localPath, syncedFolder)
309+ Log_OC .d(TAG , " Marked file as handled due to existing conflict: $localPath " )
310+ continue
311+ }
312+
313+ var (uploadEntity, upload) = result
306314
307315 // if local file deleted, upload process cannot be started or retriable thus needs to be removed
308316 if (path.isEmpty() || ! file.exists()) {
@@ -331,7 +339,7 @@ class AutoUploadWorker(
331339 )
332340
333341 if (result.isSuccess) {
334- repository.markFileAsUploaded (localPath, syncedFolder)
342+ repository.markFileAsHandled (localPath, syncedFolder)
335343 Log_OC .d(TAG , " ✅ upload completed: $localPath " )
336344 } else {
337345 Log_OC .e(
@@ -375,7 +383,11 @@ class AutoUploadWorker(
375383 uploadsStorageManager.removeUpload(upload)
376384 }
377385
378- private fun createEntityAndUpload (user : User , localPath : String , remotePath : String ): Pair <UploadEntity , OCUpload > {
386+ private fun createEntityAndUpload (
387+ user : User ,
388+ localPath : String ,
389+ remotePath : String
390+ ): Pair <UploadEntity , OCUpload >? {
379391 val (needsCharging, needsWifi, uploadAction) = getUploadSettings(syncedFolder)
380392 Log_OC .d(TAG , " creating oc upload for ${user.accountName} " )
381393
@@ -386,6 +398,12 @@ class AutoUploadWorker(
386398 accountName = user.accountName
387399 )
388400
401+ val lastUploadResult = uploadEntity?.lastResult?.let { UploadResult .fromValue(it) }
402+ if (lastUploadResult == UploadResult .SYNC_CONFLICT ) {
403+ Log_OC .w(TAG , " Conflict already exists, skipping auto-upload: $localPath " )
404+ return null
405+ }
406+
389407 val upload = (
390408 uploadEntity?.toOCUpload(null ) ? : OCUpload (
391409 localPath,
0 commit comments