removeAnyOtherFileHaveSameName

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-07-09 11:18:38 +02:00 committed by Alper Öztürk
parent dad6486a06
commit bc563681b4
2 changed files with 20 additions and 2 deletions

View file

@ -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<OCFile> = 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")

View file

@ -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 -> {