Skip to content

Commit 17155d7

Browse files
Merge pull request #16292 from nextcloud/backport/16273/stable-3.35
[stable-3.35] fix(auto-upload): handle existing sync conflicts
2 parents 06e4eaa + 7ad6bd9 commit 17155d7

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.owncloud.android.datamodel.SyncedFolder
3434
import com.owncloud.android.datamodel.SyncedFolderProvider
3535
import com.owncloud.android.datamodel.UploadsStorageManager
3636
import com.owncloud.android.db.OCUpload
37+
import com.owncloud.android.db.UploadResult
3738
import com.owncloud.android.lib.common.OwnCloudAccount
3839
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
3940
import 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,

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
@@ -63,7 +63,7 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
6363
return filtered
6464
}
6565

66-
suspend fun markFileAsUploaded(localPath: String, syncedFolder: SyncedFolder) {
66+
suspend fun markFileAsHandled(localPath: String, syncedFolder: SyncedFolder) {
6767
val syncedFolderIdStr = syncedFolder.id.toString()
6868

6969
try {

0 commit comments

Comments
 (0)