You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2012/11/02 19:52:36 UTC

android commit: CB-1808: FileEntry.moveTo across file systems incorrectly calls the success callback

Updated Branches:
  refs/heads/master d9db845b4 -> 2ac987361


CB-1808: FileEntry.moveTo across file systems incorrectly calls the success callback


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/2ac98736
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/2ac98736
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/2ac98736

Branch: refs/heads/master
Commit: 2ac98736134519ad3aeae8e5cce1532d792bcd6f
Parents: d9db845
Author: Simon MacDonald <si...@gmail.com>
Authored: Fri Nov 2 14:50:24 2012 -0400
Committer: Simon MacDonald <si...@gmail.com>
Committed: Fri Nov 2 14:50:24 2012 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileUtils.java |   34 +++++++++++++++---
 1 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/2ac98736/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index 447e4f2..973b820 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -43,6 +43,7 @@ import android.database.Cursor;
 import android.net.Uri;
 import android.os.Environment;
 import android.provider.MediaStore;
+import android.util.Log;
 import android.webkit.MimeTypeMap;
 
 //import android.app.Activity;
@@ -317,8 +318,9 @@ public class FileUtils extends CordovaPlugin {
      * @throws InvalidModificationException
      * @throws EncodingException
      * @throws JSONException
+     * @throws FileExistsException 
      */
-    private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException {
+    private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
         fileName = stripFileProtocol(fileName);
         newParent = stripFileProtocol(newParent);
 
@@ -406,6 +408,16 @@ public class FileUtils extends CordovaPlugin {
             throw new InvalidModificationException("Can't rename a file to a directory");
         }
 
+        copyAction(srcFile, destFile);
+
+        return getEntry(destFile);
+    }
+
+    /**
+     * Moved this code into it's own method so moveTo could use it when the move is across file systems
+     */
+    private void copyAction(File srcFile, File destFile)
+            throws FileNotFoundException, IOException {
         FileInputStream istream = new FileInputStream(srcFile);
         FileOutputStream ostream = new FileOutputStream(destFile);
         FileChannel input = istream.getChannel();
@@ -419,8 +431,6 @@ public class FileUtils extends CordovaPlugin {
             input.close();
             output.close();
         }
-
-        return getEntry(destFile);
     }
 
     /**
@@ -495,7 +505,7 @@ public class FileUtils extends CordovaPlugin {
      * @throws InvalidModificationException
      * @throws JSONException
      */
-    private JSONObject moveFile(File srcFile, File destFile) throws JSONException, InvalidModificationException {
+    private JSONObject moveFile(File srcFile, File destFile) throws IOException, JSONException, InvalidModificationException {
         // Renaming a file to an existing directory should fail
         if (destFile.exists() && destFile.isDirectory()) {
             throw new InvalidModificationException("Can't rename a file to a directory");
@@ -507,6 +517,12 @@ public class FileUtils extends CordovaPlugin {
             // Now we have to do things the hard way
             // 1) Copy all the old file
             // 2) delete the src file
+            copyAction(srcFile, destFile);
+            if (destFile.exists()) {
+                srcFile.delete();
+            } else {
+                throw new IOException("moved failed");
+            }
         }
 
         return getEntry(destFile);
@@ -521,8 +537,10 @@ public class FileUtils extends CordovaPlugin {
      * @throws JSONException
      * @throws IOException
      * @throws InvalidModificationException
+     * @throws NoModificationAllowedException 
+     * @throws FileExistsException 
      */
-    private JSONObject moveDirectory(File srcDir, File destinationDir) throws JSONException, InvalidModificationException {
+    private JSONObject moveDirectory(File srcDir, File destinationDir) throws IOException, JSONException, InvalidModificationException, NoModificationAllowedException, FileExistsException {
         // Renaming a file to an existing directory should fail
         if (destinationDir.exists() && destinationDir.isFile()) {
             throw new InvalidModificationException("Can't rename a file to a directory");
@@ -546,6 +564,12 @@ public class FileUtils extends CordovaPlugin {
             // Now we have to do things the hard way
             // 1) Copy all the old files
             // 2) delete the src directory
+            copyDirectory(srcDir, destinationDir);
+            if (destinationDir.exists()) {
+                removeDirRecursively(srcDir);
+            } else {
+                throw new IOException("moved failed");
+            }
         }
 
         return getEntry(destinationDir);