cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [07/19] git commit: CB-5407: Move getParent into FS modules
Date Fri, 13 Dec 2013 16:18:49 GMT
CB-5407: Move getParent into FS modules


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

Branch: refs/heads/dev
Commit: 02e82a5e9dbf1a1c3398511f23cee9990b591e4a
Parents: 06725c2
Author: Ian Clelland <iclelland@chromium.org>
Authored: Mon Dec 2 16:04:53 2013 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Dec 13 11:00:09 2013 -0500

----------------------------------------------------------------------
 src/android/ContentFilesystem.java |  7 +++++
 src/android/FileUtils.java         | 53 ++++++++-------------------------
 src/android/Filesystem.java        |  2 ++
 src/android/LocalFilesystem.java   | 12 ++++++++
 4 files changed, 34 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/02e82a5e/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 17fddcb..3b4e4c3 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -76,5 +76,12 @@ public class ContentFilesystem implements Filesystem {
 		// TODO Auto-generated method stub
 		return null;
 	}
+	@Override
+	public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL)
+			throws IOException {
+		// TODO Auto-generated method stub
+		// Can probably use same impl as LFS
+		return null;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/02e82a5e/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 8e050c5..8e3bea6 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -260,7 +260,7 @@ public class FileUtils extends CordovaPlugin {
         else if (action.equals("getParent")) {
             final String fname=args.getString(0);
             threadhelper( new FileOp( ){
-                public void run() throws JSONException {
+                public void run() throws JSONException, IOException {
                     JSONObject obj = getParent(fname);
                     callbackContext.success(obj);
                 }
@@ -848,47 +848,20 @@ public class FileUtils extends CordovaPlugin {
      * @param filePath
      * @return
      * @throws JSONException
+     * @throws IOException 
      */
-    private JSONObject getParent(String filePath) throws JSONException {
-        filePath = FileHelper.getRealPath(filePath, cordova);
-
-        if (atRootDirectory(filePath)) {
-            return getEntry(filePath);
-        }
-        return getEntry(new File(filePath).getParent());
-    }
-
-    /**
-     * Checks to see if we are at the root directory.  Useful since we are
-     * not allow to delete this directory.
-     *
-     * @param filePath to directory
-     * @return true if we are at the root, false otherwise.
-     */
-    /* TODO: Remove when no longer needed */
-    private boolean atRootDirectory(String filePath) {
-        filePath = FileHelper.getRealPath(filePath, cordova);
-
-        if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
-                filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath())
||
-                filePath.equals("/data/data/" + cordova.getActivity().getPackageName()))
{
-            return true;
+    private JSONObject getParent(String baseURLstr) throws JSONException, IOException {
+        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.getParentForLocalURL(inputURL);
+        
+        } catch (IllegalArgumentException e) {
+        	throw new MalformedURLException("Unrecognized filesystem URL");
         }
-        return false;
-    }
-
-    /**
-     * Create a File object from the passed in path
-     *
-     * @param filePath
-     * @return
-     */
-    /* TODO: Remove when no longer needed */
-    private File createFileObject(String filePath) {
-        filePath = FileHelper.getRealPath(filePath, cordova);
-
-        File file = new File(filePath);
-        return file;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/02e82a5e/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index d627d10..625cf5f 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -23,4 +23,6 @@ public interface Filesystem {
 
 	JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
 
+	JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/02e82a5e/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 3d11cf2..f2137b3 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -236,4 +236,16 @@ public class LocalFilesystem implements Filesystem {
         return metadata;
 	}
 
+	@Override
+	public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException {
+		LocalFilesystemURL newURL = new LocalFilesystemURL(inputURL.URL);
+
+    	if (!("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath))) {
+    		int end = inputURL.fullPath.endsWith("/") ? 1 : 0;
+            int lastPathStartsAt = inputURL.fullPath.lastIndexOf('/', inputURL.fullPath.length()-end)+1;
+    		newURL.fullPath = newURL.fullPath.substring(0,lastPathStartsAt);
+    	}
+    	return getEntryForLocalURL(newURL);
+	}
+
 }


Mime
View raw message