Port lmnbeyond's File fixes to Android as well

Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/8b0ada7f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/8b0ada7f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/8b0ada7f

Branch: refs/heads/master
Commit: 8b0ada7fc3bc19f17c7cc47042f8a55996fa4a2e
Parents: d28a671
Author: Ian Clelland <[email protected]>
Authored: Tue Feb 25 10:22:47 2014 -0500
Committer: Ian Clelland <[email protected]>
Committed: Tue Feb 25 10:28:16 2014 -0500

----------------------------------------------------------------------
 src/android/FileUtils.java | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8b0ada7f/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index ac29f0d..caaf573 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -445,16 +445,26 @@ public class FileUtils extends CordovaPlugin {
     }
 
     public LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
-       LocalFilesystemURL localURL;
-               for (Filesystem fs: filesystems) {
-                       if (fs != null) {
-                       localURL = fs.URLforFilesystemPath(localPath);
-                       if (localURL != null)
-                           return localURL;
-                       }
-               }
-               return null;
-       }
+        LocalFilesystemURL localURL = null;
+        int shortestFullPath = 0;
+
+        // Try all installed filesystems. Return the best matching URL
+        // (determined by the shortest resulting URL)
+        for (Filesystem fs: filesystems) {
+            if (fs != null) {
+                LocalFilesystemURL url = fs.URLforFilesystemPath(localPath);
+                if (url != null) {
+                    // A shorter fullPath implies that the filesystem is a 
better
+                    // match for the local path than the previous best.
+                    if (localURL == null || (url.fullPath.length() < 
shortestFullPath)) {
+                        localURL = url;
+                        shortestFullPath = url.fullPath.length();
+                    }
+                }
+            }
+        }
+        return localURL;
+    }
 
 
        /* helper to execute functions async and handle the result codes

Reply via email to