소스 검색

fix interrupted e2e uploads

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 2 년 전
부모
커밋
113f974fd0
1개의 변경된 파일10개의 추가작업 그리고 17개의 파일을 삭제
  1. 10 17
      app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

+ 10 - 17
app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -51,7 +51,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.e2ee.UnlockFileRemoteOperation;
 import com.owncloud.android.lib.resources.files.ChunkedFileUploadRemoteOperation;
 import com.owncloud.android.lib.resources.files.ChunkedFileUploadRemoteOperation;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
 import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
@@ -419,18 +418,6 @@ public class UploadFileOperation extends SyncOperation {
 
 
         mFile.setParentId(parent.getFileId());
         mFile.setParentId(parent.getFileId());
 
 
-        // try to unlock folder with stored token, e.g. when upload needs to be resumed or app crashed
-        // the parent folder should exist as it is a resume of a broken upload
-        if (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty()) {
-            UnlockFileRemoteOperation unlockFileOperation = new UnlockFileRemoteOperation(parent.getLocalId(),
-                mFolderUnlockToken);
-            RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client);
-
-            if (!unlockFileOperationResult.isSuccess()) {
-                return unlockFileOperationResult;
-            }
-        }
-
         // check if any parent is encrypted
         // check if any parent is encrypted
         encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
         encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
         mFile.setEncrypted(encryptedAncestor);
         mFile.setEncrypted(encryptedAncestor);
@@ -470,10 +457,15 @@ public class UploadFileOperation extends SyncOperation {
             }
             }
             /***** E2E *****/
             /***** E2E *****/
 
 
-            token = EncryptionUtils.lockFolder(parentFile, client);
-            // immediately store it
-            mUpload.setFolderUnlockToken(token);
-            uploadsStorageManager.updateUpload(mUpload);
+            // we might have an old token from interrupted upload
+            if (mFolderUnlockToken != null && !mFolderUnlockToken.isEmpty()) {
+                token = mFolderUnlockToken;
+            } else {
+                token = EncryptionUtils.lockFolder(parentFile, client);
+                // immediately store it
+                mUpload.setFolderUnlockToken(token);
+                uploadsStorageManager.updateUpload(mUpload);
+            }
 
 
             // Update metadata
             // Update metadata
             Pair<Boolean, DecryptedFolderMetadata> metadataPair = EncryptionUtils.retrieveMetadata(parentFile,
             Pair<Boolean, DecryptedFolderMetadata> metadataPair = EncryptionUtils.retrieveMetadata(parentFile,
@@ -1172,6 +1164,7 @@ public class UploadFileOperation extends SyncOperation {
                 Log_OC.d(TAG, "Cancelling upload during upload preparations.");
                 Log_OC.d(TAG, "Cancelling upload during upload preparations.");
                 mCancellationRequested.set(true);
                 mCancellationRequested.set(true);
             } else {
             } else {
+                mCancellationRequested.set(true);
                 Log_OC.e(TAG, "No upload in progress. This should not happen.");
                 Log_OC.e(TAG, "No upload in progress. This should not happen.");
             }
             }
         } else {
         } else {