You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/01/13 16:11:34 UTC

[2/6] git commit: Android: Make clear that getFile takes a path, not just a filename

Android: Make clear that getFile takes a path, not just a filename


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/d8b728ac
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/d8b728ac
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/d8b728ac

Branch: refs/heads/dev
Commit: d8b728ac2d4eb14998ddf61599816029802bb001
Parents: 9ec003a
Author: Ian Clelland <ic...@chromium.org>
Authored: Sat Jan 11 09:45:03 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Sat Jan 11 09:45:03 2014 -0500

----------------------------------------------------------------------
 src/android/FileUtils.java       | 14 +++++++-------
 src/android/Filesystem.java      |  2 +-
 src/android/LocalFilesystem.java | 10 +++++-----
 3 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8b728ac/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index d1c1b59..b04c901 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -295,20 +295,20 @@ public class FileUtils extends CordovaPlugin {
         }
         else if (action.equals("getDirectory")) {
             final String dirname=args.getString(0);
-            final String fname=args.getString(1);
+            final String path=args.getString(1);
             threadhelper( new FileOp( ){
                 public void run() throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
-                   JSONObject obj = getFile(dirname, fname, args.optJSONObject(2), true);
+                   JSONObject obj = getFile(dirname, path, args.optJSONObject(2), true);
                    callbackContext.success(obj);
                 }
             },callbackContext);
         }
         else if (action.equals("getFile")) {
             final String dirname=args.getString(0);
-            final String fname=args.getString(1);
+            final String path=args.getString(1);
             threadhelper( new FileOp( ){
                 public void run() throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
-                    JSONObject obj = getFile(dirname, fname, args.optJSONObject(2), false);
+                    JSONObject obj = getFile(dirname, path, args.optJSONObject(2), false);
                     callbackContext.success(obj);
                 }
             },callbackContext);
@@ -618,7 +618,7 @@ public class FileUtils extends CordovaPlugin {
      * Creates or looks up a file.
      *
      * @param baseURLstr base directory
-     * @param fileName file/directory to lookup or create
+     * @param path file/directory to lookup or create
      * @param options specify whether to create or not
      * @param directory if true look up directory, if false look up file
      * @return a Entry object
@@ -628,14 +628,14 @@ public class FileUtils extends CordovaPlugin {
      * @throws EncodingException
      * @throws JSONException
      */
-    private JSONObject getFile(String baseURLstr, String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
+    private JSONObject getFile(String baseURLstr, String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
         try {
         	LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
         	Filesystem fs = this.filesystemForURL(inputURL);
         	if (fs == null) {
         		throw new MalformedURLException("No installed handlers for this URL");
         	}
-        	return fs.getFileForLocalURL(inputURL, fileName, options, directory);
+        	return fs.getFileForLocalURL(inputURL, path, options, directory);
         
         } catch (IllegalArgumentException e) {
         	throw new MalformedURLException("Unrecognized filesystem URL");

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8b728ac/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 1f869c9..6aa5860 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -41,7 +41,7 @@ public abstract class Filesystem {
 
 	abstract JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
 
-	abstract JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String fileName,
+	abstract JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String path,
 			JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
 
 	abstract boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException, NoModificationAllowedException;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8b728ac/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index f0d919f..c16aefe 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -33,7 +33,7 @@ public class LocalFilesystem extends Filesystem {
 
 	@Override
 	public String filesystemPathForURL(LocalFilesystemURL url) {
-	    String path = this.fsRoot + url.fullPath;
+	    String path = new File(this.fsRoot, url.fullPath).toString();
 	    if (path.endsWith("/")) {
 	      path = path.substring(0, path.length()-1);
 	    }
@@ -66,7 +66,7 @@ public class LocalFilesystem extends Filesystem {
 
 	@Override
 	public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
-      File fp = new File(this.fsRoot + inputURL.fullPath); //TODO: Proper fs.join
+      File fp = new File(this.fsRoot, inputURL.fullPath);
 
       if (!fp.exists()) {
           throw new FileNotFoundException();
@@ -91,7 +91,7 @@ public class LocalFilesystem extends Filesystem {
 
 	@Override
 	public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
-			String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
+			String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
         boolean create = false;
         boolean exclusive = false;
 
@@ -103,8 +103,8 @@ public class LocalFilesystem extends Filesystem {
         }
 
         // Check for a ":" character in the file to line up with BB and iOS
-        if (fileName.contains(":")) {
-            throw new EncodingException("This file has a : in it's name");
+        if (path.contains(":")) {
+            throw new EncodingException("This path has an invalid \":\" in it.");
         }
 
         LocalFilesystemURL requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, fileName));