|
@@ -396,50 +396,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
File originalFile = new File(mOriginalStoragePath);
|
|
|
File expectedFile = null;
|
|
|
FileLock fileLock = null;
|
|
|
- long size = 0;
|
|
|
-
|
|
|
- boolean metadataExists = false;
|
|
|
- String token = null;
|
|
|
-
|
|
|
- ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
|
|
|
-
|
|
|
- String privateKey = arbitraryDataProvider.getValue(getAccount().name, EncryptionUtils.PRIVATE_KEY);
|
|
|
- String publicKey = arbitraryDataProvider.getValue(getAccount().name, EncryptionUtils.PUBLIC_KEY);
|
|
|
-
|
|
|
- /// check the existence of the parent folder for the file to upload
|
|
|
- String remoteParentPath = new File(getRemotePath()).getParent();
|
|
|
- remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
|
|
|
- remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;
|
|
|
- RemoteOperationResult result = grantFolderExistence(remoteParentPath, client);
|
|
|
-
|
|
|
- if (!result.isSuccess()) {
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- OCFile parent = getStorageManager().getFileByPath(remoteParentPath);
|
|
|
- mFile.setParentId(parent.getFileId());
|
|
|
-
|
|
|
- if (parent.isEncrypted()) {
|
|
|
- Log_OC.d(TAG, "encrypted upload");
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
- return encryptedUpload(client, parent);
|
|
|
- } else {
|
|
|
- Log_OC.e(TAG, "Encrypted upload on old Android API");
|
|
|
- return new RemoteOperationResult(ResultCode.OLD_ANDROID_API);
|
|
|
- }
|
|
|
- } else {
|
|
|
- Log_OC.d(TAG, "normal upload");
|
|
|
- return normalUpload(client);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
|
- private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile parentFile) {
|
|
|
- RemoteOperationResult result = null;
|
|
|
- File temporalFile = null;
|
|
|
- File originalFile = new File(mOriginalStoragePath);
|
|
|
- File expectedFile = null;
|
|
|
- FileLock fileLock = null;
|
|
|
+ long size;
|
|
|
|
|
|
boolean metadataExists = false;
|
|
|
String token = null;
|
|
@@ -453,8 +410,8 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
|
|
|
// check conditions
|
|
|
result = checkConditions (originalFile);
|
|
|
-
|
|
|
- /***** E2E *****/
|
|
|
+
|
|
|
+ /***** E2E *****/
|
|
|
|
|
|
// Lock folder
|
|
|
LockFileOperation lockFileOperation = new LockFileOperation(parentFile.getLocalId());
|
|
@@ -663,15 +620,15 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
// }
|
|
|
|
|
|
result = mUploadOperation.execute(client);
|
|
|
- if (result == null || result.isSuccess() && mUploadOperation != null) {
|
|
|
- result = mUploadOperation.execute(client);
|
|
|
+// if (result == null || result.isSuccess() && mUploadOperation != null) {
|
|
|
+// result = mUploadOperation.execute(client);
|
|
|
|
|
|
- /// move local temporal file or original file to its corresponding
|
|
|
- // location in the Nextcloud local folder
|
|
|
- if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) {
|
|
|
- result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
|
|
|
- }
|
|
|
+ /// move local temporal file or original file to its corresponding
|
|
|
+ // location in the Nextcloud local folder
|
|
|
+ if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) {
|
|
|
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
|
|
|
}
|
|
|
+// }
|
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
// upload metadata
|
|
@@ -720,15 +677,8 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
} finally {
|
|
|
mUploadStarted.set(false);
|
|
|
|
|
|
- // unlock file
|
|
|
- if (token != null) {
|
|
|
- UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parentFile.getLocalId(), token);
|
|
|
- RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client);
|
|
|
-
|
|
|
- if (!unlockFileOperationResult.isSuccess()) {
|
|
|
- Log_OC.e(TAG, "Failed to unlock " + parentFile.getLocalId());
|
|
|
- }
|
|
|
- }
|
|
|
+ // unlock folder
|
|
|
+ unlockFolder(parentFile, client, token);
|
|
|
|
|
|
if (fileLock != null) {
|
|
|
try {
|
|
@@ -765,64 +715,27 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- switch (mLocalBehaviour) {
|
|
|
- case 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("");
|
|
|
- saveUploadedFile(client);
|
|
|
- break;
|
|
|
-
|
|
|
- case FileUploader.LOCAL_BEHAVIOUR_DELETE:
|
|
|
- Log_OC.d(TAG, "Delete source file");
|
|
|
-
|
|
|
- originalFile.delete();
|
|
|
- getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath());
|
|
|
- saveUploadedFile(client);
|
|
|
- break;
|
|
|
+ // TODO on failure store token
|
|
|
+ if (result.isSuccess()) {
|
|
|
+ handleSuccessfulUpload(temporalFile, expectedFile, originalFile, client);
|
|
|
+ unlockFolder(parentFile, client, token);
|
|
|
|
|
|
- case FileUploader.LOCAL_BEHAVIOUR_COPY:
|
|
|
- if (temporalFile != null) {
|
|
|
- try {
|
|
|
- move(temporalFile, expectedFile);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- mFile.setStoragePath(expectedFile.getAbsolutePath());
|
|
|
- saveUploadedFile(client);
|
|
|
- FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
|
|
|
- break;
|
|
|
+ } else if (result.getCode() == ResultCode.SYNC_CONFLICT) {
|
|
|
+ getStorageManager().saveConflict(mFile, mFile.getEtagInConflict());
|
|
|
+ }
|
|
|
|
|
|
- case FileUploader.LOCAL_BEHAVIOUR_MOVE:
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
|
|
|
- expectedFile = new File(expectedPath);
|
|
|
+ private void unlockFolder(OCFile parentFolder, OwnCloudClient client, String token) {
|
|
|
+ if (token != null) {
|
|
|
+ UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parentFolder.getLocalId(), token);
|
|
|
+ RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client);
|
|
|
|
|
|
- try {
|
|
|
- move(originalFile, expectedFile);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- getStorageManager().deleteFileInMediaScan(originalFile.getAbsolutePath());
|
|
|
- mFile.setStoragePath(expectedFile.getAbsolutePath());
|
|
|
- saveUploadedFile(client);
|
|
|
- FileDataStorageManager.triggerMediaScan(expectedFile.getAbsolutePath());
|
|
|
- break;
|
|
|
+ if (!unlockFileOperationResult.isSuccess()) {
|
|
|
+ Log_OC.e(TAG, "Failed to unlock " + parentFolder.getLocalId());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // TODO
|
|
|
-// if (result.isSuccess()) {
|
|
|
-// handleSuccessfulUpload(temporalFile, expectedFile, originalFile, client);
|
|
|
-// } else if (result.getCode() == ResultCode.SYNC_CONFLICT) {
|
|
|
-// getStorageManager().saveConflict(mFile, mFile.getEtagInConflict());
|
|
|
-// }
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
private RemoteOperationResult checkConditions(File originalFile) {
|