@@ -17,7 +17,6 @@ import androidx.work.ForegroundInfo
1717import androidx.work.WorkerParameters
1818import com.nextcloud.client.account.User
1919import com.nextcloud.client.account.UserAccountManager
20- import com.nextcloud.client.database.entity.UploadEntity
2120import com.nextcloud.client.database.entity.toOCUpload
2221import com.nextcloud.client.database.entity.toUploadEntity
2322import com.nextcloud.client.device.PowerManagementService
@@ -27,6 +26,7 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker
2726import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
2827import com.nextcloud.client.network.ConnectivityService
2928import com.nextcloud.client.preferences.SubFolderRule
29+ import com.nextcloud.utils.extensions.isNonRetryable
3030import com.nextcloud.utils.extensions.updateStatus
3131import com.owncloud.android.R
3232import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
@@ -37,6 +37,7 @@ import com.owncloud.android.datamodel.SyncedFolderProvider
3737import com.owncloud.android.datamodel.UploadsStorageManager
3838import com.owncloud.android.db.OCUpload
3939import com.owncloud.android.db.UploadResult
40+ import com.owncloud.android.files.services.NameCollisionPolicy
4041import com.owncloud.android.lib.common.OwnCloudAccount
4142import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
4243import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -309,14 +310,14 @@ class AutoUploadWorker(
309310 )
310311
311312 try {
312- val result = createEntityAndUpload (user, localPath, remotePath)
313- if (result == null ) {
313+ val entityResult = getEntityResult (user, localPath, remotePath)
314+ if (entityResult !is AutoUploadEntityResult . Success ) {
314315 repository.markFileAsHandled(localPath, syncedFolder)
315- Log_OC .d(TAG , " Marked file as handled due to existing conflict : $localPath " )
316+ Log_OC .d(TAG , " marked file as handled: $localPath " )
316317 continue
317318 }
318319
319- var (uploadEntity, upload) = result
320+ var (uploadEntity, upload) = entityResult.data
320321
321322 // if local file deleted, upload process cannot be started or retriable thus needs to be removed
322323 if (path.isEmpty() || ! file.exists()) {
@@ -403,11 +404,7 @@ class AutoUploadWorker(
403404 }
404405
405406 @Suppress(" ReturnCount" )
406- private fun createEntityAndUpload (
407- user : User ,
408- localPath : String ,
409- remotePath : String
410- ): Pair <UploadEntity , OCUpload >? {
407+ private fun getEntityResult (user : User , localPath : String , remotePath : String ): AutoUploadEntityResult {
411408 val (needsCharging, needsWifi, uploadAction) = getUploadSettings(syncedFolder)
412409 Log_OC .d(TAG , " creating oc upload for ${user.accountName} " )
413410
@@ -419,16 +416,27 @@ class AutoUploadWorker(
419416 )
420417
421418 val lastUploadResult = uploadEntity?.lastResult?.let { UploadResult .fromValue(it) }
422- if (lastUploadResult == UploadResult .SYNC_CONFLICT ) {
423- Log_OC .w(TAG , " Conflict already exists, skipping auto-upload: $localPath " )
424- return null
419+ if (lastUploadResult?.isNonRetryable() == true ) {
420+ Log_OC .w(
421+ TAG ,
422+ " last upload failed with ${lastUploadResult.value} , skipping auto-upload: $localPath "
423+ )
424+ return AutoUploadEntityResult .NonRetryable
425425 }
426426
427427 val upload = try {
428428 uploadEntity?.toOCUpload(null ) ? : OCUpload (localPath, remotePath, user.accountName)
429429 } catch (_: IllegalArgumentException ) {
430430 Log_OC .e(TAG , " cannot construct oc upload" )
431- return null
431+ return AutoUploadEntityResult .CreationError
432+ }
433+
434+ // only valid for skip collision policy other scenarios will be handled in UploadFileOperation.java
435+ if (upload.lastResult == UploadResult .UPLOADED &&
436+ syncedFolder.nameCollisionPolicy == NameCollisionPolicy .SKIP
437+ ) {
438+ Log_OC .d(TAG , " no need to create and process this entity file is already uploaded" )
439+ return AutoUploadEntityResult .Uploaded
432440 }
433441
434442 upload.apply {
@@ -445,7 +453,7 @@ class AutoUploadWorker(
445453 }
446454 }
447455
448- return upload.toUploadEntity() to upload
456+ return AutoUploadEntityResult . Success ( upload.toUploadEntity() to upload)
449457 }
450458
451459 private fun createUploadFileOperation (upload : OCUpload , user : User ): UploadFileOperation = UploadFileOperation (
0 commit comments