From 4ef4cc200532914910019c4c410e58198b5977f5 Mon Sep 17 00:00:00 2001 From: joragua Date: Mon, 28 Oct 2024 10:55:51 +0100 Subject: [PATCH] fix: added a condition to keep the local file after a local update --- .../transfers/uploads/UploadFileInConflictUseCase.kt | 4 +++- .../android/workers/UploadFileFromFileSystemWorker.kt | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt index 40ea3501ce6..0ab30de426d 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt @@ -3,8 +3,9 @@ * * @author Abel García de Prada * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -111,6 +112,7 @@ class UploadFileInConflictUseCase( UploadFileFromFileSystemWorker.KEY_PARAM_LAST_MODIFIED to lastModifiedInSeconds, UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_PATH to uploadPath, UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_ID to uploadIdInStorageManager, + UploadFileFromFileSystemWorker.KEY_PARAM_REMOVE_LOCAL to false ) val constraints = Constraints.Builder() diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt index 12f0fb64cc9..4e17f9caa86 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt @@ -3,8 +3,9 @@ * * @author Abel García de Prada * @author Juan Carlos Garrote Gascón + * @author Jorge Aguado Recio * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -81,6 +82,7 @@ class UploadFileFromFileSystemWorker( private lateinit var behavior: UploadBehavior private lateinit var uploadPath: String private lateinit var mimetype: String + private var removeLocal: Boolean = true private var uploadIdInStorageManager: Long = -1 private lateinit var ocTransfer: OCTransfer private var fileSize: Long = 0 @@ -131,6 +133,7 @@ class UploadFileFromFileSystemWorker( val paramBehavior = workerParameters.inputData.getString(KEY_PARAM_BEHAVIOR) val paramFileSystemUri = workerParameters.inputData.getString(KEY_PARAM_LOCAL_PATH) val paramUploadId = workerParameters.inputData.getLong(KEY_PARAM_UPLOAD_ID, -1) + val paramRemoveLocal = workerParameters.inputData.getBoolean(KEY_PARAM_REMOVE_LOCAL, true) account = AccountUtils.getOwnCloudAccountByName(appContext, paramAccountName) ?: return false fileSystemPath = paramFileSystemUri.takeUnless { it.isNullOrBlank() } ?: return false @@ -139,6 +142,7 @@ class UploadFileFromFileSystemWorker( lastModified = paramLastModified ?: return false uploadIdInStorageManager = paramUploadId.takeUnless { it == -1L } ?: return false ocTransfer = retrieveUploadInfoFromDatabase() ?: return false + removeLocal = paramRemoveLocal return true } @@ -250,7 +254,7 @@ class UploadFileFromFileSystemWorker( val result = executeRemoteOperation { uploadFileOperation.execute(client) } - if (result == Unit && behavior == UploadBehavior.MOVE) { + if (result == Unit && removeLocal) { removeLocalFile() // Removed file from tmp folder } } @@ -289,7 +293,7 @@ class UploadFileFromFileSystemWorker( ) // Step 4: Remove tmp file folder after uploading - if (result == Unit && behavior == UploadBehavior.MOVE) { + if (result == Unit && removeLocal) { removeLocalFile() } } @@ -401,5 +405,6 @@ class UploadFileFromFileSystemWorker( const val KEY_PARAM_LAST_MODIFIED = "KEY_PARAM_LAST_MODIFIED" const val KEY_PARAM_UPLOAD_PATH = "KEY_PARAM_UPLOAD_PATH" const val KEY_PARAM_UPLOAD_ID = "KEY_PARAM_UPLOAD_ID" + const val KEY_PARAM_REMOVE_LOCAL = "KEY_REMOVE_LOCAL" } }