From ebc406b5a22f958e4f944fa8ba59535eafdd24ce Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 5 May 2022 15:23:53 +0200 Subject: [PATCH 1/6] File upload: force MKCOL request to be run before PUT. --- .../drive/operations/UploadFileOperation.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index 5d972a0b..7e76045e 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -95,6 +95,10 @@ public class UploadFileOperation extends RemoteOperation { } } + if (!createRemoteFolder(targetPath, client)) { + return new RemoteOperationResult(ResultCode.UNKNOWN_ERROR); + } + final UploadFileRemoteOperation uploadOperation = buildUploadOperation(file, targetPath); // Execute UploadFileOperation @@ -112,27 +116,10 @@ public class UploadFileOperation extends RemoteOperation { resultCode = uploadResult.getCode(); mustRestart = false; } else { - //Si les répértoires ou mettre le fichier n'existe pas, on les ajoutes. if (uploadResult.getCode() == ResultCode.CONFLICT ) { resultCode = ResultCode.CONFLICT; - Log.d(TAG, "Catched a conflict result for : "+file.getName()+", create missing remote path then retry"); - final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); - final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true ); - try{ - RemoteOperationResult createFolderResult = createFolderOperation.execute(client ); - - if (!createFolderResult.isSuccess() && createFolderResult.getCode() != ResultCode.FOLDER_ALREADY_EXISTS) { - resultCode = createFolderResult.getCode(); - Log.e(TAG, createFolderResult.getLogMessage()); - mustRestart = false; - syncedState.setLocalLastModified(this.previousLastModified); - } - }catch(Exception e) { - Log.e(TAG, e.toString() ); - syncedState.setLocalLastModified(this.previousLastModified); - mustRestart = false; - } - + Log.d(TAG, "Catched a conflict result for : "+file.getName()); + mustRestart = false; } else if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) { resultCode = ResultCode.QUOTA_EXCEEDED; mustRestart = false; @@ -147,7 +134,7 @@ public class UploadFileOperation extends RemoteOperation { if (mustRestart) { if (this.restartCounter < 1) { this.restartCounter += 1; - //if we encounter more than three times same error, stop trying to download. + //if we encounter more than one time same error, stop trying to upload. return this.run(client); } else { syncedState.setLocalLastModified(this.previousLastModified); //Revert syncFileState to its previous state @@ -207,4 +194,26 @@ public class UploadFileOperation extends RemoteOperation { return new RemoteOperationResult(ocsResult.getCode()); } } + + + /** + * Create remote parent folder of the file if missing + * @param targetPath + * @param client + * @return + */ + public boolean createRemoteFolder(String targetPath, OwnCloudClient client) { + final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); + final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true ); + try{ + final RemoteOperationResult createFolderResult = createFolderOperation.execute(client ); + if (createFolderResult.isSuccess() || createFolderResult.getCode() == ResultCode.FOLDER_ALREADY_EXISTS) { + return true; + } + Log.e(TAG, createFolderResult.getLogMessage()); + } catch(Exception e) { + Log.e(TAG, e.toString() ); + } + return false; + } } -- GitLab From e9b24b10fbe6fed4094e1e92ace66a97d61cad46 Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal Date: Fri, 6 May 2022 07:28:47 +0000 Subject: [PATCH 2/6] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/operations/UploadFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index 7e76045e..d1ebc661 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -206,7 +206,7 @@ public class UploadFileOperation extends RemoteOperation { final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true ); try{ - final RemoteOperationResult createFolderResult = createFolderOperation.execute(client ); + final RemoteOperationResult createFolderResult = createFolderOperation.execute(client); if (createFolderResult.isSuccess() || createFolderResult.getCode() == ResultCode.FOLDER_ALREADY_EXISTS) { return true; } -- GitLab From e19418c30de5100856f1f442dcbf2b3bbd97a4ef Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal Date: Fri, 6 May 2022 07:29:00 +0000 Subject: [PATCH 3/6] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/operations/UploadFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index d1ebc661..ff45d02b 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -203,7 +203,7 @@ public class UploadFileOperation extends RemoteOperation { * @return */ public boolean createRemoteFolder(String targetPath, OwnCloudClient client) { - final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR)+1 ); + final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1); final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true ); try{ final RemoteOperationResult createFolderResult = createFolderOperation.execute(client); -- GitLab From 29ebbfbeda45158709fb0a115e34f40928ee3397 Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal Date: Fri, 6 May 2022 07:29:12 +0000 Subject: [PATCH 4/6] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/operations/UploadFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index ff45d02b..6c4756b7 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -212,7 +212,7 @@ public class UploadFileOperation extends RemoteOperation { } Log.e(TAG, createFolderResult.getLogMessage()); } catch(Exception e) { - Log.e(TAG, e.toString() ); + Log.e(TAG, e.toString()); } return false; } -- GitLab From da3d43fad2d6b7dbf7f33f8c18d461f58e3c845c Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal Date: Fri, 6 May 2022 07:29:25 +0000 Subject: [PATCH 5/6] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/operations/UploadFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index 6c4756b7..f0d6900f 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -118,7 +118,7 @@ public class UploadFileOperation extends RemoteOperation { } else { if (uploadResult.getCode() == ResultCode.CONFLICT ) { resultCode = ResultCode.CONFLICT; - Log.d(TAG, "Catched a conflict result for : "+file.getName()); + Log.d(TAG, "Catched a conflict result for : "+ file.getName()); mustRestart = false; } else if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) { resultCode = ResultCode.QUOTA_EXCEEDED; -- GitLab From e9fa4bc8808fb47644df2dba91ec2841ddd8dc6d Mon Sep 17 00:00:00 2001 From: Abhishek Aggarwal Date: Fri, 6 May 2022 07:29:34 +0000 Subject: [PATCH 6/6] Apply 1 suggestion(s) to 1 file(s) --- .../java/foundation/e/drive/operations/UploadFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java index f0d6900f..5b4c24ae 100644 --- a/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/UploadFileOperation.java @@ -204,7 +204,7 @@ public class UploadFileOperation extends RemoteOperation { */ public boolean createRemoteFolder(String targetPath, OwnCloudClient client) { final String remoteFolderPath = targetPath.substring(0, targetPath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1); - final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true ); + final CreateFolderRemoteOperation createFolderOperation = new CreateFolderRemoteOperation(remoteFolderPath, true); try{ final RemoteOperationResult createFolderResult = createFolderOperation.execute(client); if (createFolderResult.isSuccess() || createFolderResult.getCode() == ResultCode.FOLDER_ALREADY_EXISTS) { -- GitLab