Fixed movement of files: parent folder must be created before move; besides, extra...
authorDavid A. Velasco <dvelasco@solidgear.es>
Wed, 5 Dec 2012 11:37:19 +0000 (12:37 +0100)
committerDavid A. Velasco <dvelasco@solidgear.es>
Wed, 5 Dec 2012 11:37:37 +0000 (12:37 +0100)
src/com/owncloud/android/operations/UploadFileOperation.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

index 38a4d71..1be103b 100644 (file)
@@ -242,12 +242,16 @@ public class UploadFileOperation extends RemoteOperation {
                     } else {                                // FileUploader.LOCAL_BEHAVIOUR_MOVE
                         fileToMove = originalFile;
                     }
-                    if (!expectedFile.equals(fileToMove) && !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 veeery 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;
+                    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 veeery 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;
+                        }
                     }
                 } 
             }
index 6f5f54f..117b0b2 100644 (file)
@@ -498,8 +498,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
                 
                 getActivity().showDialog(FileDisplayActivity.DIALOG_SHORT_WAIT);
             }
-            mCurrentDialog.dismiss();
-            mCurrentDialog = null;
+            if (mCurrentDialog != null) {
+                mCurrentDialog.dismiss();
+                mCurrentDialog = null;
+            }
         }
     }
     
@@ -515,8 +517,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
             mTargetFile.setStoragePath(null);
             mContainerActivity.getStorageManager().saveFile(mTargetFile);
         }
-        mCurrentDialog.dismiss();
-        mCurrentDialog = null;
+        if (mCurrentDialog != null) {
+            mCurrentDialog.dismiss();
+            mCurrentDialog = null;
+        }
         listDirectory();
         mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
     }
@@ -524,8 +528,10 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial
     @Override
     public void onCancel(String callerTag) {
         Log.d(TAG, "REMOVAL CANCELED");
-        mCurrentDialog.dismiss();
-        mCurrentDialog = null;
+        if (mCurrentDialog != null) {
+            mCurrentDialog.dismiss();
+            mCurrentDialog = null;
+        }
     }