Browse Source

fix: on worker restart current gets deleted

Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
Jonas Mayer 1 year ago
parent
commit
dfe331e652

+ 9 - 5
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -180,13 +180,17 @@ class FilesUploadWorker(
             Log_OC.e(TAG, "Error uploading", e)
             uploadResult = RemoteOperationResult<Any?>(e)
         } finally {
-            uploadsStorageManager.updateDatabaseUploadResult(uploadResult, uploadFileOperation)
+            // only update db if operation finished and worker didn't get canceled
+            if (!(isStopped && uploadResult.isCancelled)) {
+                uploadsStorageManager.updateDatabaseUploadResult(uploadResult, uploadFileOperation)
 
-            // / notify result
-            notifyUploadResult(uploadFileOperation, uploadResult)
+                // / notify result
+                notifyUploadResult(uploadFileOperation, uploadResult)
+
+                // cancel notification
+                notificationManager.cancel(FOREGROUND_SERVICE_ID)
+            }
 
-            // cancel notification
-            notificationManager.cancel(FOREGROUND_SERVICE_ID)
         }
 
         return uploadResult

+ 1 - 1
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -1159,7 +1159,7 @@ public class FileUploader extends Service
                 try{
                     new FilesUploadHelper().cancelFileUpload(remotePath, accountManager.getUser(accountName).get(),null);
                 }catch(NoSuchElementException e){
-                    Log_OC.e(TAG,"Error cancelling current upload because user does not exist! 666");
+                    Log_OC.e(TAG,"Error cancelling current upload because user does not exist!");
                 }
             } else {
                 // Cancel for Android version <= Android 10