mirror of
https://github.com/nextcloud/android.git
synced 2025-07-23 01:02:01 +00:00
fix create logic check
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
@ -36,4 +36,12 @@ data class OfflineOperationEntity(
|
||||
|
||||
@ColumnInfo(name = ProviderTableMeta.OFFLINE_OPERATION_MODIFIED_AT)
|
||||
var modifiedAt: Long? = null
|
||||
)
|
||||
) {
|
||||
fun isRenameOrRemove(): Boolean {
|
||||
return (type is OfflineOperationType.RenameFile || type is OfflineOperationType.RemoveFile)
|
||||
}
|
||||
|
||||
fun isCreate(): Boolean {
|
||||
return (type is OfflineOperationType.CreateFile || type is OfflineOperationType.CreateFolder)
|
||||
}
|
||||
}
|
||||
|
@ -124,21 +124,24 @@ class OfflineOperationsWorker(
|
||||
): OfflineOperationResult? = withContext(Dispatchers.IO) {
|
||||
val ocFile = fileDataStorageManager.getFileByDecryptedRemotePath(operation.path)
|
||||
|
||||
// it checks if file exists on remote and eTag is changed or not
|
||||
if (ocFile != null && ocFile.remoteId != null && isFileChanged(ocFile)) {
|
||||
if (isCreateConflict(operation, ocFile)) {
|
||||
Log_OC.w(TAG, "Offline operation skipped, file already exists: $operation")
|
||||
notificationManager.showConflictResolveNotification(ocFile, operation)
|
||||
notificationManager.showConflictResolveNotification(ocFile!!, operation)
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
// worker cannot rename or remove non existing file thus operation needs to be removed
|
||||
if ((ocFile == null || ocFile.remoteId == null) &&
|
||||
(operation.type is OfflineOperationType.RenameFile || operation.type is OfflineOperationType.RemoveFile)
|
||||
) {
|
||||
if (isNonExistentFileForRenameOrRemove(operation, ocFile)) {
|
||||
Log_OC.w(TAG, "Offline operation skipped, same file name used for create operation: $operation")
|
||||
fileDataStorageManager.offlineOperationDao.delete(operation)
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
if (isFileChangedForRenameOrRemove(operation, ocFile)) {
|
||||
Log_OC.w(TAG, "Offline operation skipped, file changed: $operation")
|
||||
notificationManager.showConflictResolveNotification(ocFile!!, operation)
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
return@withContext when (val type = operation.type) {
|
||||
is OfflineOperationType.CreateFolder -> createFolder(operation, client)
|
||||
is OfflineOperationType.CreateFile -> createFile(operation, client)
|
||||
@ -151,6 +154,18 @@ class OfflineOperationsWorker(
|
||||
}
|
||||
}
|
||||
|
||||
private fun isCreateConflict(operation: OfflineOperationEntity, ocFile: OCFile?): Boolean {
|
||||
return ocFile != null && operation.filename == ocFile.fileName && operation.isCreate()
|
||||
}
|
||||
|
||||
private fun isNonExistentFileForRenameOrRemove(operation: OfflineOperationEntity, ocFile: OCFile?): Boolean {
|
||||
return operation.isRenameOrRemove() && (ocFile == null || ocFile.remoteId == null)
|
||||
}
|
||||
|
||||
private fun isFileChangedForRenameOrRemove(operation: OfflineOperationEntity, ocFile: OCFile?): Boolean {
|
||||
return operation.isRenameOrRemove() && ocFile?.remoteId != null && isFileChanged(ocFile)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private suspend fun createFolder(
|
||||
operation: OfflineOperationEntity,
|
||||
|
Reference in New Issue
Block a user