@@ -18,7 +18,6 @@ import com.nextcloud.client.network.ConnectivityService
18
18
import com.nextcloud.model.OfflineOperationType
19
19
import com.nextcloud.model.WorkerState
20
20
import com.nextcloud.model.WorkerStateLiveData
21
- import com.nextcloud.utils.extensions.toOCFile
22
21
import com.owncloud.android.datamodel.FileDataStorageManager
23
22
import com.owncloud.android.datamodel.OCFile
24
23
import com.owncloud.android.lib.common.OwnCloudClient
@@ -31,6 +30,7 @@ import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
31
30
import com.owncloud.android.operations.CreateFolderOperation
32
31
import com.owncloud.android.operations.RemoveFileOperation
33
32
import com.owncloud.android.operations.RenameFileOperation
33
+ import com.owncloud.android.utils.MimeTypeUtil
34
34
import com.owncloud.android.utils.theme.ViewThemeUtils
35
35
import kotlinx.coroutines.Dispatchers
36
36
import kotlinx.coroutines.NonCancellable
@@ -120,29 +120,30 @@ class OfflineOperationsWorker(
120
120
client : OwnCloudClient
121
121
): OfflineOperationResult ? = withContext(Dispatchers .IO ) {
122
122
val ocFile = fileDataStorageManager.getFileByDecryptedRemotePath(operation.path)
123
+ val path = (operation.path)
123
124
124
- if (isCreateConflict(operation, ocFile)) {
125
- Log_OC .w(TAG , " Offline operation skipped, file already exists: $operation " )
126
- notificationManager.showConflictResolveNotification(ocFile!! , operation)
125
+ if (path == null ) {
126
+ Log_OC .w(TAG , " Offline operation skipped, file path is null: $operation " )
127
127
return @withContext null
128
128
}
129
129
130
- if (isNonExistentFileForRenameOrRemove(operation, ocFile)) {
131
- Log_OC .w(TAG , " Offline operation skipped, same file name used for create operation: $operation " )
132
- fileDataStorageManager.offlineOperationDao.delete(operation)
133
- return @withContext null
134
- }
130
+ if (isRemoteFileExists(path)) {
131
+ Log_OC .w(TAG , " Offline operation skipped, file already exists: $operation " )
132
+
133
+ if (operation.isRenameOrRemove()) {
134
+ fileDataStorageManager.offlineOperationDao.delete(operation)
135
+ notificationManager.showConflictNotificationForDeleteOrRemoveOperation(operation)
136
+ } else {
137
+ notificationManager.showConflictResolveNotification(ocFile!! , operation)
138
+ }
135
139
136
- if (isFileChangedForRenameOrRemove(operation, ocFile)) {
137
- Log_OC .w(TAG , " Offline operation skipped, file changed: $operation " )
138
- notificationManager.showConflictResolveNotification(ocFile!! , operation)
139
140
return @withContext null
140
141
}
141
142
142
143
return @withContext when (val type = operation.type) {
143
144
is OfflineOperationType .CreateFolder -> createFolder(operation, client)
144
145
is OfflineOperationType .CreateFile -> createFile(operation, client)
145
- is OfflineOperationType .RenameFile -> ocFile?. let { renameFile(operation, it, client) }
146
+ is OfflineOperationType .RenameFile -> renameFile(operation, client)
146
147
is OfflineOperationType .RemoveFile -> ocFile?.let { removeFile(it, client) }
147
148
else -> {
148
149
Log_OC .d(TAG , " Unsupported operation type: $type " )
@@ -151,19 +152,6 @@ class OfflineOperationsWorker(
151
152
}
152
153
}
153
154
154
- private fun isCreateConflict (operation : OfflineOperationEntity , ocFile : OCFile ? ): Boolean {
155
- return ocFile != null && ocFile.remoteId != null && (operation.filename == ocFile.fileName)
156
- && operation.isCreate()
157
- }
158
-
159
- private fun isNonExistentFileForRenameOrRemove (operation : OfflineOperationEntity , ocFile : OCFile ? ): Boolean {
160
- return operation.isRenameOrRemove() && (ocFile == null || ocFile.remoteId == null )
161
- }
162
-
163
- private fun isFileChangedForRenameOrRemove (operation : OfflineOperationEntity , ocFile : OCFile ? ): Boolean {
164
- return operation.isRenameOrRemove() && ocFile?.remoteId != null && isFileChanged(ocFile)
165
- }
166
-
167
155
@Suppress(" DEPRECATION" )
168
156
private suspend fun createFolder (
169
157
operation : OfflineOperationEntity ,
@@ -199,20 +187,10 @@ class OfflineOperationsWorker(
199
187
}
200
188
201
189
@Suppress(" DEPRECATION" )
202
- private suspend fun renameFile (
203
- operation : OfflineOperationEntity ,
204
- ocFile : OCFile ,
205
- client : OwnCloudClient
206
- ): OfflineOperationResult {
207
- val ocFileRemotePath = ocFile.remotePath
208
- if (ocFileRemotePath == null ) {
209
- Log_OC .w(TAG , " Rename offline operation is cancelled, remote path is null" )
210
- return null
211
- }
212
-
190
+ private suspend fun renameFile (operation : OfflineOperationEntity , client : OwnCloudClient ): OfflineOperationResult {
213
191
val renameFileOperation = withContext(NonCancellable ) {
214
192
val operationType = (operation.type as OfflineOperationType .RenameFile )
215
- RenameFileOperation (ocFileRemotePath , operationType.newName, fileDataStorageManager)
193
+ RenameFileOperation (operation.path , operationType.newName, fileDataStorageManager)
216
194
}
217
195
218
196
return renameFileOperation.execute(client) to renameFileOperation
@@ -281,15 +259,16 @@ class OfflineOperationsWorker(
281
259
}
282
260
283
261
@Suppress(" DEPRECATION" )
284
- private fun isFileChanged (file : OCFile ): Boolean {
262
+ private fun isRemoteFileExists (remotePath : String ): Boolean {
263
+ val mimeType = MimeTypeUtil .getMimeTypeFromPath(remotePath)
264
+ val isFolder = MimeTypeUtil .isFolder(mimeType)
285
265
val client = ClientFactoryImpl (context).create(user)
286
- val remoteFile = if (file. isFolder) {
287
- ReadFolderRemoteOperation (file. remotePath).execute(client)
266
+ val remoteFile = if (isFolder) {
267
+ ReadFolderRemoteOperation (remotePath).execute(client)
288
268
} else {
289
- ReadFileRemoteOperation (file. remotePath).execute(client)
269
+ ReadFileRemoteOperation (remotePath).execute(client)
290
270
}
291
271
292
- val remoteETag = remoteFile.toOCFile()?.get(0 )?.etag
293
- return file.etag != remoteETag
272
+ return remoteFile.isSuccess
294
273
}
295
274
}
0 commit comments