|
@@ -421,6 +421,8 @@ public class UploadFileOperation extends SyncOperation {
|
|
channel = new RandomAccessFile(mFile.getStoragePath(), "rw").getChannel();
|
|
channel = new RandomAccessFile(mFile.getStoragePath(), "rw").getChannel();
|
|
fileLock = channel.tryLock();
|
|
fileLock = channel.tryLock();
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
|
|
+ // this basically means that the file is on SD card
|
|
|
|
+ // try to copy file to temporary dir if it doesn't exist
|
|
if (temporalFile == null) {
|
|
if (temporalFile == null) {
|
|
String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
|
|
String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
|
|
mFile.setStoragePath(temporalPath);
|
|
mFile.setStoragePath(temporalPath);
|
|
@@ -428,24 +430,18 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
|
|
|
result = copy(originalFile, temporalFile);
|
|
result = copy(originalFile, temporalFile);
|
|
|
|
|
|
- if (result != null) {
|
|
|
|
- return result;
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (result == null) {
|
|
if (temporalFile.length() == originalFile.length()) {
|
|
if (temporalFile.length() == originalFile.length()) {
|
|
channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
|
|
channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
|
|
fileLock = channel.tryLock();
|
|
fileLock = channel.tryLock();
|
|
} else {
|
|
} else {
|
|
- while (temporalFile.length() != originalFile.length()) {
|
|
|
|
- Files.deleteIfExists(Paths.get(temporalPath));
|
|
|
|
- result = copy(originalFile, temporalFile);
|
|
|
|
-
|
|
|
|
- if (result != null) {
|
|
|
|
- return result;
|
|
|
|
- } else {
|
|
|
|
- channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").
|
|
|
|
- getChannel();
|
|
|
|
- fileLock = channel.tryLock();
|
|
|
|
- }
|
|
|
|
|
|
+ Files.deleteIfExists(Paths.get(temporalPath));
|
|
|
|
+ result = copy(originalFile, temporalFile);
|
|
|
|
+
|
|
|
|
+ if (result == null) {
|
|
|
|
+ channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").
|
|
|
|
+ getChannel();
|
|
|
|
+ fileLock = channel.tryLock();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -455,14 +451,18 @@ public class UploadFileOperation extends SyncOperation {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- result = mUploadOperation.execute(client);
|
|
|
|
|
|
+ if (result == null) {
|
|
|
|
+ result = mUploadOperation.execute(client);
|
|
|
|
+
|
|
|
|
+ /// move local temporal file or original file to its corresponding
|
|
|
|
+ // location in the ownCloud 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 ownCloud local folder
|
|
|
|
- if (!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED) {
|
|
|
|
- result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
Log_OC.d(TAG, mOriginalStoragePath + " not exists anymore");
|
|
Log_OC.d(TAG, mOriginalStoragePath + " not exists anymore");
|
|
result = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
|
|
result = new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND);
|
|
@@ -486,6 +486,7 @@ public class UploadFileOperation extends SyncOperation {
|
|
if (temporalFile != null && !originalFile.equals(temporalFile)) {
|
|
if (temporalFile != null && !originalFile.equals(temporalFile)) {
|
|
temporalFile.delete();
|
|
temporalFile.delete();
|
|
}
|
|
}
|
|
|
|
+
|
|
if (result == null) {
|
|
if (result == null) {
|
|
result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
|
|
result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
|
|
}
|
|
}
|