-
- /// check location of local file, and copy to a temporal file to upload it if not in its corresponding directory
- String targetLocalPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile);
- if (!originalStoragePath.equals(targetLocalPath)) {
- File ocLocalFolder = new File(FileStorageUtils.getSavePath(mAccount.name));
- originalFile = new File(originalStoragePath);
- if (!mMoveLocalFile) {
- // the file must be copied to the ownCloud local folder
-
- if (ocLocalFolder.getUsableSpace() < originalFile.length()) {
- result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
- return result;
-
- } else {
- String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
- mFile.setStoragePath(temporalPath);
- temporalFile = new File(temporalPath);
- if (!originalStoragePath.equals(temporalPath)) { // preventing weird but possible situation
- InputStream in = new FileInputStream(originalFile);
- OutputStream out = new FileOutputStream(temporalFile);
+
+ String expectedPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); // /
+ // not
+ // before
+ // getAvailableRemotePath()
+ // !!!
+ expectedFile = new File(expectedPath);
+
+ // / check location of local file; if not the expected, copy to a
+ // temporal file before upload (if COPY is the expected behaviour)
+ if (!mOriginalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
+
+ if (FileStorageUtils.getUsableSpace(mAccount.name) < originalFile.length()) {
+ result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
+ return result; // error condition when the file should be
+ // copied
+
+ } else {
+ String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+ mFile.setStoragePath(temporalPath);
+ temporalFile = new File(temporalPath);
+ if (!mOriginalStoragePath.equals(temporalPath)) { // preventing
+ // weird
+ // but
+ // possible
+ // situation
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ File temporalParent = temporalFile.getParentFile();
+ temporalParent.mkdirs();
+ if (!temporalParent.isDirectory()) {
+ throw new IOException("Unexpected error: parent directory could not be created");
+ }
+ temporalFile.createNewFile();
+ if (!temporalFile.isFile()) {
+ throw new IOException("Unexpected error: target file could not be created");
+ }
+ in = new FileInputStream(originalFile);
+ out = new FileOutputStream(temporalFile);