From bb20395e98c1b417ab5aead6f43bedaf6ca7b253 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 1 Mar 2017 11:47:20 +0100 Subject: [PATCH] Revert "Revert "Try to fix changes between upload behaviour"" This reverts commit e7da3ede5e4771eb04048e0bd71e525a99390245. # Conflicts: # src/com/owncloud/android/operations/UploadFileOperation.java --- .../operations/UploadFileOperation.java | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 04cd11cb0f..d764bf8315 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -76,6 +76,8 @@ public class UploadFileOperation extends SyncOperation { public static final int CREATED_AS_INSTANT_PICTURE = 1; public static final int CREATED_AS_INSTANT_VIDEO = 2; + private String expectedPath; + public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) { // MIME type @@ -346,7 +348,7 @@ public class UploadFileOperation extends SyncOperation { throw new OperationCancelledException(); } - String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); + expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); expectedFile = new File(expectedPath); /// copy the file locally before uploading @@ -391,15 +393,8 @@ public class UploadFileOperation extends SyncOperation { /// move local temporal file or original file to its corresponding // location in the ownCloud local folder if (result.isSuccess()) { - if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) { - String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); - if (mOriginalStoragePath.equals(temporalPath)) { - // delete local file is was pre-copied in temporary folder (see .ui.helpers.UriUploader) - temporalFile = new File(temporalPath); - temporalFile.delete(); - } - mFile.setStoragePath(""); +<<<<<<< HEAD } else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_DELETE) { originalFile.delete(); getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath()); @@ -414,6 +409,8 @@ public class UploadFileOperation extends SyncOperation { } FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath()); } +======= +>>>>>>> parent of e7da3ed... Revert "Try to fix changes between upload behaviour" } else if (result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED ) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); @@ -453,6 +450,36 @@ public class UploadFileOperation extends SyncOperation { if (result.isSuccess()) { saveUploadedFile(client); + if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) { + String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); + if (mOriginalStoragePath.equals(temporalPath)) { + // delete local file is was pre-copied in temporary folder (see .ui.helpers.UriUploader) + temporalFile = new File(temporalPath); + temporalFile.delete(); + } + mFile.setStoragePath(""); + + } else if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_DELETE) { + originalFile.delete(); + } else { + mFile.setStoragePath(expectedPath); + + if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY + try { + move(temporalFile, expectedFile); + } catch (IOException e) { + e.printStackTrace(); + } + } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE + try { + move(originalFile, expectedFile); + } catch (IOException e) { + e.printStackTrace(); + } + getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath()); + } + FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath()); + } } else if (result.getCode() == ResultCode.SYNC_CONFLICT) { getStorageManager().saveConflict(mFile, mFile.getEtagInConflict()); }