@@ -61,56 +61,49 @@ class OfflineOperationsWorker(
6161 private val notificationManager = OfflineOperationsNotificationManager (context, viewThemeUtils)
6262 private var repository = OfflineOperationsRepository (fileDataStorageManager)
6363
64- @Suppress(" TooGenericExceptionCaught" )
6564 override suspend fun doWork (): Result = withContext(Dispatchers .IO ) {
6665 val jobName = inputData.getString(JOB_NAME )
67- Log_OC .d(
68- TAG ,
69- " $jobName -----------------------------------\n " +
70- " OfflineOperationsWorker started" +
71- " \n -----------------------------------"
72- )
66+ Log_OC .d(TAG , " $jobName --- OfflineOperationsWorker started ---" )
7367
7468 if (! isNetworkAndServerAvailable()) {
75- Log_OC .d (TAG , " OfflineOperationsWorker cancelled, no internet connection" )
69+ Log_OC .w (TAG , " No internet connection. Retrying later. " )
7670 return @withContext Result .retry()
7771 }
7872
7973 val client = clientFactory.create(user)
80- notificationManager.start()
8174
75+ notificationManager.start()
8276 var operations = fileDataStorageManager.offlineOperationDao.getAll()
83- val totalOperations = operations.size
77+ val result = processOperations(operations, client)
78+ notificationManager.dismissNotification()
79+
80+ return @withContext result
81+ }
82+
83+ @Suppress(" TooGenericExceptionCaught" )
84+ private suspend fun processOperations (operations : List <OfflineOperationEntity >, client : OwnCloudClient ): Result {
85+ val totalOperationSize = operations.size
8486
85- return @withContext try {
86- for (index in 0 .. < operations.size) {
87+ return try {
88+ operations.forEachIndexed { index, operation ->
8789 try {
88- val operation = operations[index]
8990 val result = executeOperation(operation, client)
90- val isSuccess = handleResult(
91- operation,
92- totalOperations,
93- index,
94- result
95- )
96-
97- if (! isSuccess) {
98- Log_OC .e(TAG , " Offline operation skipped: $operation " )
99- continue
91+ val success = handleResult(operation, totalOperationSize, index, result)
92+
93+ if (! success) {
94+ Log_OC .e(TAG , " Skipped (failed to handle result): $operation " )
10095 }
10196 } catch (e: Exception ) {
102- Log_OC .e(TAG , " Offline operation skipped, exception caught : $e " )
97+ Log_OC .e(TAG , " Skipped ( exception) : $e " )
10398 }
10499 }
105100
106- Log_OC .i(TAG , " OfflineOperationsWorker successfully completed" )
101+ Log_OC .i(TAG , " OfflineOperationsWorker completed successfully. " )
107102 WorkerStateLiveData .instance().setWorkState(WorkerState .OfflineOperationsCompleted )
108103 Result .success()
109104 } catch (e: Exception ) {
110- Log_OC .e(TAG , " OfflineOperationsWorker terminated : $e " )
105+ Log_OC .e(TAG , " Processing failed : $e " )
111106 Result .failure()
112- } finally {
113- notificationManager.dismissNotification()
114107 }
115108 }
116109
@@ -159,7 +152,8 @@ class OfflineOperationsWorker(
159152 }
160153
161154 private fun isCreateConflict (operation : OfflineOperationEntity , ocFile : OCFile ? ): Boolean {
162- return ocFile != null && operation.filename == ocFile.fileName && operation.isCreate()
155+ return ocFile != null && ocFile.remoteId != null && (operation.filename == ocFile.fileName)
156+ && operation.isCreate()
163157 }
164158
165159 private fun isNonExistentFileForRenameOrRemove (operation : OfflineOperationEntity , ocFile : OCFile ? ): Boolean {
0 commit comments