Bug fixed: Upload fails
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / UploadFileOperation.java
index 42ca738..bf0d060 100644 (file)
@@ -258,7 +258,6 @@ public class UploadFileOperation extends RemoteOperation {
                                     (nRead = in.read(data, 0, data.length)) != -1) {
                                 out.write(data, 0, nRead);
                             }
-
                             out.flush();
 
                         } else {
@@ -278,6 +277,11 @@ public class UploadFileOperation extends RemoteOperation {
                             }
                         }
 
+                        if (mCancellationRequested.get()) {
+                            result = new RemoteOperationResult(new OperationCancelledException());
+                        }
+
+
                     } catch (Exception e) {
                         result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED);
                         return result;
@@ -300,7 +304,7 @@ public class UploadFileOperation extends RemoteOperation {
                     }
                 }
             }
-            localCopyPassed = true;
+            localCopyPassed = (result == null);
 
             /// perform the upload
             if ( mChunked &&
@@ -318,37 +322,38 @@ public class UploadFileOperation extends RemoteOperation {
             }
             if (!mCancellationRequested.get()) {
                 result = mUploadOperation.execute(client);
-            }
-            /// 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) {
-                    mFile.setStoragePath(null);
 
-                } else {
-                    mFile.setStoragePath(expectedPath);
-                    File fileToMove = null;
-                    if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY
-                                                // ; see where temporalFile was
-                                                // set
-                        fileToMove = temporalFile;
-                    } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE
-                        fileToMove = originalFile;
-                    }
-                    if (!expectedFile.equals(fileToMove)) {
-                        File expectedFolder = expectedFile.getParentFile();
-                        expectedFolder.mkdirs();
-                        if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) {
-                            mFile.setStoragePath(null); // forget the local file
-                            // by now, treat this as a success; the file was
-                            // uploaded; the user won't like that the local file
-                            // is not linked, but this should be a very rare
-                            // fail;
-                            // the best option could be show a warning message
-                            // (but not a fail)
-                            // result = new
-                            // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
-                            // return result;
+                /// 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) {
+                        mFile.setStoragePath(null);
+
+                    } else {
+                        mFile.setStoragePath(expectedPath);
+                        File fileToMove = null;
+                        if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY
+                            // ; see where temporalFile was
+                            // set
+                            fileToMove = temporalFile;
+                        } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE
+                            fileToMove = originalFile;
+                        }
+                        if (!expectedFile.equals(fileToMove)) {
+                            File expectedFolder = expectedFile.getParentFile();
+                            expectedFolder.mkdirs();
+                            if (!expectedFolder.isDirectory() || !fileToMove.renameTo(expectedFile)) {
+                                mFile.setStoragePath(null); // forget the local file
+                                // by now, treat this as a success; the file was
+                                // uploaded; the user won't like that the local file
+                                // is not linked, but this should be a very rare
+                                // fail;
+                                // the best option could be show a warning message
+                                // (but not a fail)
+                                // result = new
+                                // RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
+                                // return result;
+                            }
                         }
                     }
                 }
@@ -357,7 +362,6 @@ public class UploadFileOperation extends RemoteOperation {
         } catch (Exception e) {
             // TODO something cleaner with cancellations
             if (mCancellationRequested.get()) {
-                mUploadOperation.cancel();
                 result = new RemoteOperationResult(new OperationCancelledException());
             } else {
                 result = new RemoteOperationResult(e);