Remove duplicate usage of unlock folder operation and mimic success

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-04 14:42:07 +02:00
parent de1dcfe93a
commit be3fc9f5d4
No known key found for this signature in database
GPG Key ID: 4E577DC593B59BDF
3 changed files with 17 additions and 42 deletions

View File

@ -235,19 +235,9 @@ class FileUploadWorker(
}
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, operation: UploadFileOperation) {
if (operation.decryptedRemotePath == operation.uploadedDecyptedRemotePath) {
// TODO
// This is not ideal fix. When uploading file to the encrypted folder server returns 404 FILE_NOT_FOUND
// However file upload successfully completed. This fix mimic success, if upload successfully completed with
// receiving path
val newResult = RemoteOperationResult<Void>(ResultCode.OK)
uploadsStorageManager.updateDatabaseUploadResult(newResult, operation)
notificationManager.dismissOldErrorNotification(operation)
} else {
if (!isStopped || !result.isCancelled) {
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
notifyUploadResult(operation, result)
}
if (!isStopped || !result.isCancelled) {
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
notifyUploadResult(operation, result)
}
notificationManager.dismissWorkerNotifications()

View File

@ -256,7 +256,7 @@ public class UploadsStorageManager extends Observable {
* @param localPath path of the file to upload in the device storage
* @return 1 if file status was updated, else 0.
*/
public int updateUploadStatus(long id, UploadStatus status, UploadResult result, String remotePath,
private int updateUploadStatus(long id, UploadStatus status, UploadResult result, String remotePath,
String localPath) {
//Log_OC.v(TAG, "Updating "+filepath+" with uploadStatus="+status +" and result="+result);

View File

@ -459,6 +459,7 @@ public class UploadFileOperation extends SyncOperation {
boolean metadataExists = false;
String token = null;
Object object = null;
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProviderImpl(getContext());
String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY);
@ -490,7 +491,7 @@ public class UploadFileOperation extends SyncOperation {
// Update metadata
EncryptionUtilsV2 encryptionUtilsV2 = new EncryptionUtilsV2();
Object object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
object = EncryptionUtils.downloadFolderMetadata(parentFile, client, mContext, user);
if (object instanceof DecryptedFolderMetadataFileV1 decrypted && decrypted.getMetadata() != null) {
metadataExists = true;
}
@ -702,9 +703,6 @@ public class UploadFileOperation extends SyncOperation {
"",
arbitraryDataProvider,
user);
// unlock
result = EncryptionUtils.unlockFolderV1(parentFile, client, token);
} else {
DecryptedFolderMetadataFile metadata = (DecryptedFolderMetadataFile) object;
encryptionUtilsV2.addFileToMetadata(
@ -725,9 +723,6 @@ public class UploadFileOperation extends SyncOperation {
mContext,
user,
getStorageManager());
// unlock
result = EncryptionUtils.unlockFolder(parentFile, client, token);
}
encryptedTempFile.delete();
@ -759,20 +754,20 @@ public class UploadFileOperation extends SyncOperation {
result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
}
if (result.isSuccess()) {
setUploadedDecyptedRemotePath(mFile.getDecryptedRemotePath());
}
logResult(result, mFile.getStoragePath(), mFile.getRemotePath());
// unlock must be done always
if (token != null) {
RemoteOperationResult<Void> unlockFolderResult = EncryptionUtils.unlockFolder(parentFile,
client,
token);
// Unlock in final block
if (object instanceof DecryptedFolderMetadataFileV1) {
RemoteOperationResult unlockFolderV1 = EncryptionUtils.unlockFolderV1(parentFile, client, token);
if (!unlockFolderResult.isSuccess()) {
result = unlockFolderResult;
if (!unlockFolderV1.isSuccess()) {
result = unlockFolderV1;
}
} else {
RemoteOperationResult unlockFolderV2 = EncryptionUtils.unlockFolder(parentFile, client, token);
if (!unlockFolderV2.isSuccess()) {
result = unlockFolderV2;
}
}
}
@ -1002,16 +997,6 @@ public class UploadFileOperation extends SyncOperation {
}
}
private String uploadedDecyptedRemotePath;
public String getUploadedDecyptedRemotePath(){
return uploadedDecyptedRemotePath;
}
public void setUploadedDecyptedRemotePath(String uploadedDecyptedRemotePath){
this.uploadedDecyptedRemotePath = uploadedDecyptedRemotePath;
}
private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) {
if (result.isSuccess()) {
Log_OC.i(TAG, "Upload of " + sourcePath + " to " + targetPath + ": " + result.getLogMessage());