Fixed. When define as instant upload path a path that does not exist, a crash is...
authorjabarros <jabarros@solidgear.es>
Wed, 15 Oct 2014 09:21:37 +0000 (11:21 +0200)
committerjabarros <jabarros@solidgear.es>
Wed, 15 Oct 2014 09:21:37 +0000 (11:21 +0200)
src/com/owncloud/android/operations/CreateFolderOperation.java

index b0e7ed9..4df8b3d 100644 (file)
@@ -84,21 +84,36 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
        }
     }
 
-    
     /**
      * Save new directory in local database
      */
     public void saveFolderInDB() {
-        OCFile newDir = new OCFile(mRemotePath);
-        newDir.setMimetype("DIR");
-        long parentId = getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
-        newDir.setParentId(parentId);
-        newDir.setModificationTimestamp(System.currentTimeMillis());
-        getStorageManager().saveFile(newDir);
+        if (mCreateFullPath && getStorageManager().
+                getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
+                                                                                    // of remote path
+                                                                                    // is not created 
+            String[] subFolders = mRemotePath.split("/");
+            String composedRemotePath = "/";
 
-        Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
+            // For each antecesor folders create them recursively
+            for (int i=0; i<subFolders.length; i++) {
+                String subFolder =  subFolders[i];
+                if (!subFolder.isEmpty()) {
+                    composedRemotePath = composedRemotePath + subFolder + "/";
+                    mRemotePath = composedRemotePath;
+                    saveFolderInDB();
+                }
+            }
+        } else { // Create directory on DB
+            OCFile newDir = new OCFile(mRemotePath);
+            newDir.setMimetype("DIR");
+            long parentId = getStorageManager().
+                    getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
+            newDir.setParentId(parentId);
+            newDir.setModificationTimestamp(System.currentTimeMillis());
+            getStorageManager().saveFile(newDir);
 
+            Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
+        }
     }
-
-
 }