diff --git a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt index 819dc0122a..1f2a94511d 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt @@ -19,6 +19,7 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker.Companion.currentUpload import com.nextcloud.client.network.Connectivity import com.nextcloud.client.network.ConnectivityService import com.owncloud.android.MainApp +import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.UploadsStorageManager import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus @@ -31,6 +32,7 @@ import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation import com.owncloud.android.lib.resources.files.model.RemoteFile import com.owncloud.android.operations.UploadFileOperation +import com.owncloud.android.ui.helpers.FileOperationsHelper import com.owncloud.android.utils.FileUtil import java.io.File import java.util.concurrent.Semaphore @@ -48,6 +50,9 @@ class FileUploadHelper { @Inject lateinit var uploadsStorageManager: UploadsStorageManager + @Inject + lateinit var fileStorageManager: FileDataStorageManager + init { MainApp.getAppComponent().inject(this) } @@ -314,7 +319,7 @@ class FileUploadHelper { // For file conflicts check old file remote path upload.remotePath == currentUploadFileOperation.remotePath || upload.remotePath == currentUploadFileOperation.oldFile!! - .remotePath + .remotePath } else { upload.remotePath == currentUploadFileOperation.remotePath } @@ -349,6 +354,15 @@ class FileUploadHelper { backgroundJobManager.startFilesUploadJob(user) } + fun removeAnyOtherFileHaveSameName(newFile: OCFile, fileOperationsHelper: FileOperationsHelper) { + val parentFile: OCFile? = fileStorageManager.getFileById(newFile.parentId) + val folderContent: List = fileStorageManager.getFolderContent(parentFile, false) + + folderContent.firstOrNull { it.fileName == newFile.fileName }?.let { replacedFile -> + fileOperationsHelper.removeFiles(listOf(replacedFile), false, true) + } + } + fun retryUpload(upload: OCUpload, user: User) { Log_OC.d(this, "retry upload") diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt index 0567a215c7..1901c0c506 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt @@ -86,7 +86,6 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener private fun setupOnConflictDecisionMadeListener(upload: OCUpload?) { listener = OnConflictDecisionMadeListener { decision: Decision? -> val file = newFile // local file got changed, so either upload it or replace it again by server - // version val user = user.orElseThrow { RuntimeException() } when (decision) { Decision.CANCEL -> {} @@ -94,12 +93,17 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener upload?.let { FileUploadHelper.instance().removeFileUpload(it.remotePath, it.accountName) } + FileUploadHelper.instance().uploadUpdatedFile( user, arrayOf(file), localBehaviour, NameCollisionPolicy.OVERWRITE ) + + file?.let { + FileUploadHelper.instance().removeAnyOtherFileHaveSameName(file, fileOperationsHelper) + } } Decision.KEEP_BOTH -> {