cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [26/40] git commit: Port lmnbeyond's File fixes to Android as well
Date Fri, 28 Feb 2014 21:36:03 GMT
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 <iclelland@chromium.org>
Authored: Tue Feb 25 10:22:47 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
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


Mime
View raw message