You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/02/11 00:22:27 UTC
[01/50] git commit: CB-5407: Cleanup
Updated Branches:
refs/heads/master cfdb4ed4e -> 6a3bc14a3
CB-5407: Cleanup
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/25506177
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/25506177
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/25506177
Branch: refs/heads/master
Commit: 2550617750d4b81c66066455417537c800411625
Parents: 9f3bb54
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Nov 28 21:42:19 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:00:35 2013 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 76 ++++++++++-------------------------
src/android/LocalFilesystem.java | 20 ---------
2 files changed, 21 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/25506177/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 868e34e..00483bc 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -33,17 +33,11 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URLDecoder;
-import java.nio.channels.FileChannel;
import java.util.ArrayList;
/**
@@ -632,55 +626,23 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject requestFileSystem(int type) throws IOException, JSONException {
JSONObject fs = new JSONObject();
+ LocalFilesystemURL rootURL;
if (type == TEMPORARY) {
- File fp;
fs.put("name", "temporary");
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
- // Create the cache dir if it doesn't exist.
- fp.mkdirs();
- fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/"));
- } else {
- fp = new File("/data/data/" + cordova.getActivity().getPackageName() + "/cache/");
- // Create the cache dir if it doesn't exist.
- fp.mkdirs();
- fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName() + "/cache/"));
- }
+ rootURL = new LocalFilesystemURL("filesystem://localhost/temporary/");
}
else if (type == PERSISTENT) {
fs.put("name", "persistent");
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- fs.put("root", getEntry(Environment.getExternalStorageDirectory()));
- } else {
- fs.put("root", getEntry("/data/data/" + cordova.getActivity().getPackageName()));
- }
+ rootURL = new LocalFilesystemURL("filesystem://localhost/persistent/");
}
else {
throw new IOException("No filesystem of type requested");
}
- fs.put("root", makeEntryForPath("/", type, true));
+ Filesystem rootFs = this.filesystemForURL(rootURL);
+ fs.put("root", rootFs.getEntryForLocalURL(rootURL));
return fs;
}
- public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
- JSONObject entry = new JSONObject();
-
- int end = path.endsWith("/") ? 1 : 0;
- String[] parts = path.substring(0,path.length()-end).split("/",1);
- String name = parts[parts.length-1];
- entry.put("isFile", !isDir);
- entry.put("isDirectory", isDir);
- entry.put("name", name);
- entry.put("fullPath", path);
- // The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", fsType);
-
- return entry;
-
- }
/**
* Returns a JSON object representing the given File.
*
@@ -690,18 +652,22 @@ public class FileUtils extends CordovaPlugin {
*/
@Deprecated
public static JSONObject getEntry(File file) throws JSONException {
- return makeEntryForPath(file.getAbsolutePath(), 0, file.isDirectory());
- }
-
- /**
- * Returns a JSON Object representing a directory on the device's file system
- *
- * @param path to the directory
- * @return
- * @throws JSONException
- */
- private JSONObject getEntry(String path) throws JSONException {
- return getEntry(new File(path));
+ String path = file.getAbsolutePath();
+ Boolean isDir = file.isDirectory();
+ JSONObject entry = new JSONObject();
+
+ int end = path.endsWith("/") ? 1 : 0;
+ String[] parts = path.substring(0,path.length()-end).split("/",1);
+ String name = parts[parts.length-1];
+ entry.put("isFile", !isDir);
+ entry.put("isDirectory", isDir);
+ entry.put("name", name);
+ entry.put("fullPath", path);
+ // The file system can't be specified, as it would lead to an infinite loop,
+ // but the filesystem type can
+ entry.put("filesystem", 0);
+
+ return entry;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/25506177/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 2613329..adb3ef6 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -86,25 +86,6 @@ public class LocalFilesystem implements Filesystem {
}
}
- /**
- * If the path starts with a '/' just return that file object. If not construct the file
- * object from the path passed in and the file name.
- *
- * @param dirPath root directory
- * @param fileName new file name
- * @return
- */
- private File createFileObject(String dirPath, String fileName) {
- File fp = null;
- if (fileName.startsWith("/")) {
- fp = new File(this.fsRoot + fileName);
- } else {
- fp = new File(this.fsRoot + File.separator + dirPath + File.separator + fileName);
- }
- return fp;
- }
-
-
@Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
String fileName, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
@@ -575,7 +556,6 @@ public class LocalFilesystem implements Filesystem {
@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
- File file = new File(filesystemPathForURL(inputURL));
boolean append = false;
if (offset > 0) {
[35/50] git commit: CB-5916: Android: Add config preference for
Android persistent storage location
Posted by st...@apache.org.
CB-5916: Android: Add config preference for Android persistent storage location
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/3fa16d04
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3fa16d04
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3fa16d04
Branch: refs/heads/master
Commit: 3fa16d04cd1b5e68ad8075c22ba549c4fa24fff5
Parents: aaadfec
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Jan 27 23:29:44 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 09:52:09 2014 -0500
----------------------------------------------------------------------
doc/index.md | 41 +++++++++++++++++++++++
src/android/FileUtils.java | 73 +++++++++++++++++++++++++++--------------
2 files changed, 89 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fa16d04/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 192cae5..003ba0e 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -39,6 +39,47 @@ on the subject. For an overview of other storage options, refer to Cordova's
\* _These platforms do not support `FileReader.readAsArrayBuffer` nor `FileWriter.write(blob)`._
+## Android Quirks
+
+### Android Persistent storage location
+
+There are multiple valid locations to store persistent files on an Android
+device. See [this page](http://developer.android.com/guide/topics/data/data-storage.html)
+for an extensive discussion of the various possibilities.
+
+Previous versions of thie plugin would choose the location of the temporary and
+persistent files on startup, based on whether the device claimed that the SD
+Card (or equivalent storage partition) was mounted. If the SD Card was mounted,
+or if a large internal storage partition was available (such as on Nexus
+devices,) then the persistent files would be stored in the root of that space.
+This meant that all Cordova apps could see all of the files available on the
+card.
+
+If the SD card was not available, then previous versions would store data under
+/data/data/<packageId>, which isolates apps from each other, but may still
+cause data to be shared between users.
+
+It is now possible to choose whether to store files in the internal file
+storage location, or using the previous logic, with a preference in your
+application's config.xml file. To do this, add one of these two lines to
+config.xml:
+
+ <preference name="AndroidPersistentFileLocation" value="Internal" />
+
+ <preference name="AndroidPersistentFileLocation" value="Compatibility" />
+
+Without this line, the File plugin will not initialize, and your application
+will not start.
+
+If your application has previously been shipped to users, using an older (pre-
+1.0) version of this plugin, and has stored files in the persistent filesystem,
+then you should set the preference to "Compatibility". Switching the location to
+"Internal" would mean that existing users who upgrade their application may be
+unable to access their previously-stored files, depending on their device.
+
+If your application is new, or has never previously stored files in the
+persistent filesystem, then the "internal" setting is generally recommended.
+
## BlackBerry Quirks
`DirectoryEntry.removeRecursively()` may fail with a `ControlledAccessException` in the following cases:
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fa16d04/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index ac24413..7983be1 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.cordova.file;
+import android.app.Activity;
import android.net.Uri;
import android.os.Environment;
import android.util.Base64;
@@ -93,33 +94,55 @@ public class FileUtils extends CordovaPlugin {
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.filesystems = new ArrayList<Filesystem>();
+
+ String tempRoot = null;
+ String persistentRoot = null;
+
+ Activity activity = cordova.getActivity();
+ String packageName = activity.getPackageName();
- File fp;
- String tempRoot;
- String persistentRoot;
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
- tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/";
- } else {
- persistentRoot = "/data/data/" + cordova.getActivity().getPackageName();
- tempRoot = "/data/data/" + cordova.getActivity().getPackageName() + "/cache/";
+ String location = activity.getIntent().getStringExtra("androidpersistentfilelocation");
+ if (!(location.equalsIgnoreCase("internal") || location.equalsIgnoreCase("compatibility"))) {
+ Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
+ activity.finish();
}
- // Create the cache dir if it doesn't exist.
- fp = new File(tempRoot);
- fp.mkdirs();
-
- // Register initial filesystems
- // Note: The temporary and persistent filesystems need to be the first two
- // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
- // per spec.
- this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot));
- this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
- this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
-
- // Initialize static plugin reference for deprecated getEntry method
- if (filePlugin == null) {
- FileUtils.filePlugin = this;
+ else {
+ if (location.equalsIgnoreCase("internal")) {
+ persistentRoot = activity.getFilesDir().getAbsolutePath();
+ tempRoot = activity.getCacheDir().getAbsolutePath();
+ } else {
+ /*
+ * Fall-back to compatibility mode -- this is the logic implemented in
+ * earlier versions of this plugin, and should be maintained here so
+ * that apps which were originally deployed with older versions of the
+ * plugin can continue to provide access to files stored under those
+ * versions.
+ */
+ File fp;
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
+ tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/Android/data/" + packageName + "/cache/";
+ } else {
+ persistentRoot = "/data/data/" + packageName;
+ tempRoot = "/data/data/" + packageName + "/cache/";
+ }
+ // Create the cache dir if it doesn't exist.
+ fp = new File(tempRoot);
+ fp.mkdirs();
+ }
+ // Register initial filesystems
+ // Note: The temporary and persistent filesystems need to be the first two
+ // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
+ // per spec.
+ this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot));
+ this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
+ this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
+
+ // Initialize static plugin reference for deprecated getEntry method
+ if (filePlugin == null) {
+ FileUtils.filePlugin = this;
+ }
}
}
[30/50] git commit: Add backwards-compatibility shim for file-transfer
Posted by st...@apache.org.
Add backwards-compatibility shim for file-transfer
Since file-transfer constructs its own FileEntry objects, we cant change the return values of getEntry so much.
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/ca3813ca
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/ca3813ca
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/ca3813ca
Branch: refs/heads/master
Commit: ca3813caa1612ef76bf451da645c2f9f90ce0193
Parents: 5268af3
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jan 22 23:36:47 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 23 09:00:54 2014 -0500
----------------------------------------------------------------------
src/android/Filesystem.java | 2 ++
src/android/LocalFilesystem.java | 2 ++
2 files changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/ca3813ca/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 560cc85..904f728 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -33,6 +33,8 @@ public abstract class Filesystem {
// The file system can't be specified, as it would lead to an infinite loop,
// but the filesystem name can be.
entry.put("filesystemName", fsName);
+ // Backwards compatibility
+ entry.put("filesystem", "temporary".equals(fsName) ? 0 : 1);
return entry;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/ca3813ca/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 0e46d1e..ebcbaec 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -84,6 +84,8 @@ public class LocalFilesystem extends Filesystem {
// But we can specify the name of the FS, and the rest can be reconstructed
// in JS.
entry.put("filesystemName", inputURL.filesystemName);
+ // Backwards compatibility
+ entry.put("filesystem", "temporary".equals(name) ? 0 : 1);
return entry;
} catch (JSONException e) {
throw new IOException();
[37/50] git commit: CB-5916: Android: Add "/files/" to persistent
files path
Posted by st...@apache.org.
CB-5916: Android: Add "/files/" to persistent files path
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/28c21bfb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/28c21bfb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/28c21bfb
Branch: refs/heads/master
Commit: 28c21bfbeceeb81950981105a39219b7702e5907
Parents: 40df005
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 10:05:22 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 10:05:22 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/28c21bfb/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 7983be1..f9a36a7 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -108,7 +108,7 @@ public class FileUtils extends CordovaPlugin {
}
else {
if (location.equalsIgnoreCase("internal")) {
- persistentRoot = activity.getFilesDir().getAbsolutePath();
+ persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
tempRoot = activity.getCacheDir().getAbsolutePath();
} else {
/*
[27/50] git commit: CB-5810 [BlackBerry10] resolve local:/// paths
(application assets)
Posted by st...@apache.org.
CB-5810 [BlackBerry10] resolve local:/// paths (application assets)
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/3fe44cf5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3fe44cf5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3fe44cf5
Branch: refs/heads/master
Commit: 3fe44cf5df65a11638cca5f9da870a00bcc258bd
Parents: 54a8e7d
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Thu Jan 16 16:00:25 2014 -0500
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Thu Jan 16 16:00:25 2014 -0500
----------------------------------------------------------------------
src/blackberry10/index.js | 7 ++++++
www/blackberry10/resolveLocalFileSystemURI.js | 29 ++++++++++++++++------
2 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fe44cf5/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 9e4cfd3..9c9c3e2 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -6,5 +6,12 @@ module.exports = {
isSandboxed : function (success, fail, args, env) {
new PluginResult(args, env).ok(require("lib/webview").getSandbox() === "1");
+ },
+
+ resolveLocalPath : function (success, fail, args, env) {
+ var homeDir = window.qnx.webplatform.getApplication().getEnv("HOME").replace("/data", "/app/native/"),
+ path = homeDir + JSON.parse(decodeURIComponent(args[0])).substring(9);
+ require("lib/webview").setSandbox(false);
+ new PluginResult(args, env).ok(path);
}
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3fe44cf5/www/blackberry10/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/resolveLocalFileSystemURI.js b/www/blackberry10/resolveLocalFileSystemURI.js
index fd0e217..a3f62f7 100644
--- a/www/blackberry10/resolveLocalFileSystemURI.js
+++ b/www/blackberry10/resolveLocalFileSystemURI.js
@@ -24,7 +24,7 @@ var fileUtils = require('./BB10Utils'),
module.exports = function (uri, success, fail) {
- var decodedURI = decodeURI(uri).replace(/filesystem:/, '').replace(/local:\/\//, '').replace(/file:\/\//, ''),
+ var decodedURI = decodeURI(uri).replace(/filesystem:/, '').replace(/file:\/\//, ''),
failNotFound = function () {
fail(FileError.NOT_FOUND_ERR);
},
@@ -47,11 +47,24 @@ module.exports = function (uri, success, fail) {
);
};
- cordova.exec(
- resolveURI,
- failNotFound,
- 'org.apache.cordova.file',
- 'setSandbox',
- [!fileUtils.isOutsideSandbox(decodedURI)]
- );
+ if (decodedURI.substring(0, 8) === 'local://') {
+ cordova.exec(
+ function (path) {
+ decodedURI = path;
+ resolveURI();
+ },
+ failNotFound,
+ 'org.apache.cordova.file',
+ 'resolveLocalPath',
+ [decodedURI]
+ );
+ } else {
+ cordova.exec(
+ resolveURI,
+ failNotFound,
+ 'org.apache.cordova.file',
+ 'setSandbox',
+ [!fileUtils.isOutsideSandbox(decodedURI)]
+ );
+ }
};
[34/50] git commit: iOS: Add config preference for iOS persistent
storage location
Posted by st...@apache.org.
iOS: Add config preference for iOS persistent storage location
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/aaadfecb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/aaadfecb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/aaadfecb
Branch: refs/heads/master
Commit: aaadfecb7498673fba170d367c400fa258ab2d18
Parents: 590b930
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Jan 24 11:35:06 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Jan 24 11:38:20 2014 -0500
----------------------------------------------------------------------
doc/index.md | 31 +++++++++++++++++++++++++++++++
src/ios/CDVFile.h | 2 --
src/ios/CDVFile.m | 45 ++++++++++++++++++++++++++++++++-------------
3 files changed, 63 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 0c26700..192cae5 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -55,3 +55,34 @@ on the subject. For an overview of other storage options, refer to Cordova's
- `FileReader.readAsText(blob, encoding)`
- The `encoding` parameter is not supported, and UTF-8 encoding is always in effect.
+### iOS Persistent storage location
+
+There are two valid locations to store persistent files on an iOS device: the
+Documents directory and the Library directory. Previous versions of thie plugin
+only ever stored persistent files in the Documents directory. This had the
+side-effect of making all of an application's files visible in iTunes, which
+was often unintended, especially for applications which handle lots of small
+files, rather than producing complete documents for export, which is the
+intended purpose of the directory.
+
+It is now possible to choose whether to store files in the documents or library
+directory, with a preference in your application's config.xml file. To do this,
+add one of these two lines to config.xml:
+
+ <preference name="iosPersistentFileLocation" value="Library" />
+
+ <preference name="iosPersistentFileLocation" value="Documents" />
+
+Without this line, the File plugin will not initialize, and your application
+will not start.
+
+If your application has previously been shipped to users, using an older (pre-
+1.0) version of this plugin, and has stored files in the persistent filesystem,
+then you should set the preference to "Documents". Switching the location to
+"Library" would mean that existing users who upgrade their application would be
+unable to access their previously-stored files.
+
+If your application is new, or has never previously stored files in the
+persistent filesystem, then the "Library" setting is generally recommended,
+unless your application's purpose is to generate document files for users to
+consume externally.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 85a76b0..477fad7 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -90,8 +90,6 @@ typedef int CDVFileError;
NSString* appDocsPath;
NSString* appLibraryPath;
NSString* appTempPath;
- NSString* persistentPath;
- NSString* temporaryPath;
NSMutableArray* fileSystems_;
BOOL userHasAllowed;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aaadfecb/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index f4f1cbb..e685929 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -153,7 +153,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@implementation CDVFile
-@synthesize appDocsPath, appLibraryPath, appTempPath, persistentPath, temporaryPath, userHasAllowed, fileSystems=fileSystems_;
+@synthesize appDocsPath, appLibraryPath, appTempPath, userHasAllowed, fileSystems=fileSystems_;
- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
[fileSystems_ addObject:fs];
@@ -182,35 +182,54 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
}
}
+@synthesize viewController=_viewController;
+- (void)setViewController:(UIViewController *)newViewController
+{
+ if (_viewController != newViewController) {
+ _viewController = newViewController;
+
+ NSString *location = nil;
+ if([_viewController isKindOfClass:[CDVViewController class]]) {
+ CDVViewController *vc = (CDVViewController *)_viewController;
+ NSMutableDictionary *settings = vc.settings;
+ location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString];
+ NSAssert(
+ [location isEqualToString:@"library"] || [location isEqualToString:@"documents"],
+ @"File plugin configuration error: Please set ios-persistent-file-location in config.xml to one of \"library\" (for new applications) or \"documents\" (for compatibility with previous versions)");
+ }
+
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
+ if ([location isEqualToString:@"library"]) {
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
+ } else {
+ // Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appDocsPath]];
+ }
+ [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
+ }
+}
+
+
- (id)initWithWebView:(UIWebView*)theWebView
{
self = (CDVFile*)[super initWithWebView:theWebView];
if (self) {
filePlugin = self;
-// @throw (@"Error!");
[NSURLProtocol registerClass:[CDVFilesystemURLProtocol class]];
fileSystems_ = [[NSMutableArray alloc] initWithCapacity:3];
- // get the temporary directory path
+ // Get the Library directory path
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
self.appLibraryPath = [paths objectAtIndex:0];
+ // Get the Temporary directory path
self.appTempPath = [NSTemporaryDirectory()stringByStandardizingPath]; // remove trailing slash from NSTemporaryDirectory()
- [fileSystems_ addObject:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:[paths objectAtIndex:0]]];
-
- // get the documents directory path
+ // Get the Documents directory path
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
self.appDocsPath = [paths objectAtIndex:0];
- [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths objectAtIndex:0]]];
-
- self.persistentPath = [NSString stringWithFormat:@"/%@", [self.appDocsPath lastPathComponent]];
- self.temporaryPath = [NSString stringWithFormat:@"/%@", [self.appTempPath lastPathComponent]];
- // NSLog(@"docs: %@ - temp: %@", self.appDocsPath, self.appTempPath);
-
- [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
}
[24/50] git commit: Android: Properly format content urls
Posted by st...@apache.org.
Android: Properly format content urls
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/73dbfb6c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/73dbfb6c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/73dbfb6c
Branch: refs/heads/master
Commit: 73dbfb6c1f0b42b9825e08856b8da277f0b30450
Parents: 2a225e3
Author: Ian Clelland <ic...@chromium.org>
Authored: Sat Jan 11 09:58:08 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Jan 13 10:10:47 2014 -0500
----------------------------------------------------------------------
www/android/FileSystem.js | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/73dbfb6c/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index 2099a99..d0db194 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -23,6 +23,9 @@ FILESYSTEM_PROTOCOL = "filesystem";
module.exports = {
__format__: function(fullPath) {
+ if (this.name === 'content') {
+ return 'content:/' + encodeURI(fullPath);
+ }
var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
return FILESYSTEM_PROTOCOL + '://localhost' + path;
}
[13/50] git commit: Android: Better support for content urls and
cross-filesystem copy/move ops
Posted by st...@apache.org.
Android: Better support for content urls and cross-filesystem copy/move ops
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/68b29ccb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/68b29ccb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/68b29ccb
Branch: refs/heads/master
Commit: 68b29ccb4b5b0a115f018a058651daf0111cd709
Parents: b788277
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 7 10:12:57 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 7 10:27:30 2014 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 63 +++++++++++++++++++++++--
src/android/FileUtils.java | 25 ++--------
src/android/Filesystem.java | 2 +
src/android/LocalFilesystem.java | 81 ++++++++++++++++-----------------
src/android/ReadFileCallback.java | 4 +-
5 files changed, 107 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68b29ccb/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index e19f5bc..03a1939 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -1,8 +1,10 @@
package org.apache.cordova.file;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
@@ -51,39 +53,63 @@ public class ContentFilesystem implements Filesystem {
throw new IOException();
}
}
+
@Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
String fileName, JSONObject options, boolean directory) throws IOException {
throw new IOException("Cannot create content url");
}
+
@Override
public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL)
throws NoModificationAllowedException {
- throw new NoModificationAllowedException("Cannot remove content url");
+
+ String filePath = filesystemPathForURL(inputURL);
+ File file = new File(filePath);
+ try {
+ this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
+ MediaStore.Images.Media.DATA + " = ?",
+ new String[] { filePath });
+ } catch (UnsupportedOperationException t) {
+ // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator.
+ // The ContentResolver applies only when the file was registered in the
+ // first case, which is generally only the case with images.
+ }
+ return file.delete();
}
+
@Override
public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL)
throws NoModificationAllowedException {
throw new NoModificationAllowedException("Cannot remove content url");
}
+
@Override
public JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL)
throws FileNotFoundException {
// TODO Auto-generated method stub
return null;
}
+
@Override
public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
// 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;
+ 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);
}
+
@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move)
@@ -92,12 +118,32 @@ public class ContentFilesystem implements Filesystem {
// TODO Auto-generated method stub
return null;
}
+
@Override
public void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
ReadFileCallback readFileCallback) throws IOException {
- // TODO Auto-generated method stub
+ int numBytesToRead = end - start;
+ byte[] bytes = new byte[numBytesToRead];
+ String contentType;
+
+ File file = new File(this.filesystemPathForURL(inputURL));
+ contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+ InputStream inputStream = new FileInputStream(file);
+ int numBytesRead = 0;
+ try {
+ if (start > 0) {
+ inputStream.skip(start);
+ }
+ while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
+ numBytesToRead -= numBytesRead;
+ }
+ } finally {
+ inputStream.close();
+ }
+ readFileCallback.handleData(bytes, contentType);
}
+
@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws NoModificationAllowedException {
@@ -135,4 +181,11 @@ public class ContentFilesystem implements Filesystem {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) {
+ String path = filesystemPathForURL(inputURL);
+ File file = new File(path);
+ return file.exists();
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68b29ccb/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 25ea6b4..20a2700 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -61,6 +61,8 @@ public class FileUtils extends CordovaPlugin {
public static int QUOTA_EXCEEDED_ERR = 10;
public static int TYPE_MISMATCH_ERR = 11;
public static int PATH_EXISTS_ERR = 12;
+
+ public static int UNKNOWN_ERR = 1000;
public static int TEMPORARY = 0;
public static int PERSISTENT = 1;
@@ -312,9 +314,8 @@ public class FileUtils extends CordovaPlugin {
final String fname=args.getString(0);
threadhelper( new FileOp( ){
public void run() throws NoModificationAllowedException, InvalidModificationException, MalformedURLException {
- boolean success= remove(fname);
+ boolean success = remove(fname);
if (success) {
- notifyDelete(fname);
callbackContext.success();
} else {
callbackContext.error(FileUtils.NO_MODIFICATION_ALLOWED_ERR);
@@ -439,6 +440,8 @@ public class FileUtils extends CordovaPlugin {
callbackContext.error(FileUtils.ENCODING_ERR);
} else if(e instanceof TypeMismatchException ) {
callbackContext.error(FileUtils.TYPE_MISMATCH_ERR);
+ } else {
+ callbackContext.error(FileUtils.UNKNOWN_ERR);
}
}
}
@@ -446,24 +449,6 @@ public class FileUtils extends CordovaPlugin {
}
/**
- * Need to check to see if we need to clean up the content store
- *
- * @param filePath the path to check
- */
- private void notifyDelete(String filePath) {
- String newFilePath = FileHelper.getRealPath(filePath, cordova);
- try {
- this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
- MediaStore.Images.Media.DATA + " = ?",
- new String[] { newFilePath });
- } catch (UnsupportedOperationException t) {
- // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator.
- // The ContentResolver applies only when the file was registered in the
- // first case, which is generally only the case with images.
- }
- }
-
- /**
* Allows the user to look up the Entry for a file or directory referred to by a local URI.
*
* @param url of the file/directory to look up
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68b29ccb/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 7dd99f2..ba2c7bd 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -42,4 +42,6 @@ public interface Filesystem {
LocalFilesystemURL URLforFilesystemPath(String path);
+ boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL);
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68b29ccb/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 6634661..6c16e45 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -83,8 +83,7 @@ public class LocalFilesystem implements Filesystem {
@Override
public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
- File fp = null;
- fp = new File(this.fsRoot + inputURL.fullPath); //TODO: Proper fs.join
+ File fp = new File(this.fsRoot + inputURL.fullPath); //TODO: Proper fs.join
if (!fp.exists()) {
throw new FileNotFoundException();
@@ -282,7 +281,7 @@ public class LocalFilesystem implements Filesystem {
* @param destination represents the destination file
* @return a File object that represents the destination
*/
- private File createDestination(String newName, File fp, File destination) {
+ private File createDestination(String newName, String oldName, File destination) {
File destFile = null;
// I know this looks weird but it is to work around a JSON bug.
@@ -293,7 +292,7 @@ public class LocalFilesystem implements Filesystem {
if (newName != null) {
destFile = new File(destination.getAbsolutePath() + File.separator + newName);
} else {
- destFile = new File(destination.getAbsolutePath() + File.separator + fp.getName());
+ destFile = new File(destination.getAbsolutePath() + File.separator + oldName);
}
return destFile;
}
@@ -461,42 +460,33 @@ public class LocalFilesystem implements Filesystem {
return makeEntryForFile(destinationDir, fsType);
}
-
@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
-
- String newFileName = this.filesystemPathForURL(srcURL);
+ // Check to see if the destination directory exists
String newParent = this.filesystemPathForURL(destURL);
-
-
File destinationDir = new File(newParent);
if (!destinationDir.exists()) {
// The destination does not exist so we should fail.
throw new FileNotFoundException("The source does not exist");
}
-
+
+ // Figure out where we should be copying to
+ String originalName = srcURL.URL.getLastPathSegment();
+ final File destination = createDestination(newName, originalName, destinationDir);
if (LocalFilesystem.class.isInstance(srcFs)) {
-
/* Same FS, we can shortcut with NSFileManager operations */
-
-
- File source = new File(newFileName);
+ String srcFilesystemPath = this.filesystemPathForURL(srcURL);
+ File source = new File(srcFilesystemPath);
if (!source.exists()) {
// The file/directory we are copying doesn't exist so we should fail.
throw new FileNotFoundException("The source does not exist");
}
- // Figure out where we should be copying to
- File destination = createDestination(newName, source, destinationDir);
-
- //Log.d(LOG_TAG, "Source: " + source.getAbsolutePath());
- //Log.d(LOG_TAG, "Destin: " + destination.getAbsolutePath());
-
// Check to see if source and destination are the same file
if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
throw new InvalidModificationException("Can't copy a file onto itself");
@@ -510,36 +500,37 @@ public class LocalFilesystem implements Filesystem {
}
} else {
if (move) {
- JSONObject newFileEntry = moveFile(source, destination, destURL.filesystemType);
-
-/* // If we've moved a file given its content URI, we need to clean up.
- // TODO: Move this to where it belongs, in cross-fs mv code below.
- if (srcURL.URL.getScheme().equals("content")) {
- notifyDelete(fileName);
- }
-*/
- return newFileEntry;
+ return moveFile(source, destination, destURL.filesystemType);
} else {
return copyFile(source, destination, destURL.filesystemType);
}
}
-
} else {
-/* // Need to copy the hard way
- srcFs.readFileAtURL(srcURL, 0, -1, new ReadFileCallback() {
- void run(data, mimetype, errorcode) {
- if (data != null) {
- //write data to file
- // send success message -- call original callback?
+ // Need to copy the hard way
+ // First, check to see that we can do it
+ if (!move || srcFs.canRemoveFileAtLocalURL(srcURL)) {
+ srcFs.readFileAtURL(srcURL, 0, -1, new ReadFileCallback() {
+ public void handleData(byte[] data, String contentType) throws IOException {
+ if (data != null) {
+ //write data to file
+ FileOutputStream os = new FileOutputStream(destination);
+ os.write(data);
+ os.close();
+ } else {
+ throw new IOException("Cannot read file at source URL");
+ }
}
- // error
- }
- });
- return null; // Async, will return later
-*/
+ });
+ if (move) {
+ // Delete original
+ srcFs.removeFileAtLocalURL(srcURL);
+ }
+ return makeEntryForFile(destination, destURL.filesystemType);
+ } else {
+ throw new NoModificationAllowedException("Cannot move file at source URL");
+ }
}
- return null;
}
@Override
@@ -632,5 +623,11 @@ public class LocalFilesystem implements Filesystem {
}
+ @Override
+ public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) {
+ String path = filesystemPathForURL(inputURL);
+ File file = new File(path);
+ return file.exists();
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/68b29ccb/src/android/ReadFileCallback.java
----------------------------------------------------------------------
diff --git a/src/android/ReadFileCallback.java b/src/android/ReadFileCallback.java
index 77bb7da..b8ba02d 100644
--- a/src/android/ReadFileCallback.java
+++ b/src/android/ReadFileCallback.java
@@ -1,5 +1,7 @@
package org.apache.cordova.file;
+import java.io.IOException;
+
public interface ReadFileCallback {
- public void handleData(byte[] data, String contentType);
+ public void handleData(byte[] data, String contentType) throws IOException;
}
[20/50] git commit: Android: Make clear that getFile takes a path,
not just a filename
Posted by st...@apache.org.
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/master
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));
[50/50] git commit: CB-5980 Updated version and RELEASENOTES.md for
release 1.0.0
Posted by st...@apache.org.
CB-5980 Updated version and RELEASENOTES.md for release 1.0.0
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/6a3bc14a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/6a3bc14a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/6a3bc14a
Branch: refs/heads/master
Commit: 6a3bc14a35cf77c833058de2d219654f025f5448
Parents: 3c0ba72
Author: Steven Gill <st...@gmail.com>
Authored: Wed Feb 5 17:53:59 2014 -0800
Committer: Steven Gill <st...@gmail.com>
Committed: Wed Feb 5 17:53:59 2014 -0800
----------------------------------------------------------------------
RELEASENOTES.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++
plugin.xml | 2 +-
2 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6a3bc14a/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 2fd1c95..a79a4e3 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -49,3 +49,78 @@
* CB-5128: added repo + issue tag to plugin.xml for file plugin
* CB-5015 [BlackBerry10] Add missing dependency for File.slice
* [CB-5010] Incremented plugin version on dev branch.
+
+### 1.0.0 (Feb 05, 2014)
+* CB-5974: Use safe 'Compatibilty' mode by default
+* CB-5915: CB-5916: Reorganize preference code to make defaults possible
+* CB-5974: Android: Don't allow File operations to continue when not configured
+* CB-5960: ios: android: Properly handle parent references in getFile/getDirectory
+* [ubuntu] adopt to recent changes
+* Add default FS root to new FS objects
+* CB-5899: Make DirectoryReader.readEntries return properly formatted Entry objects
+* Add constuctor params to FileUploadResult related to CB-2421
+* Fill out filesystem attribute of entities returned from resolveLocalFileSystemURL
+* CB-5916: Create documents directories if they don't exist
+* CB-5915: Create documents directories if they don't exist
+* CB-5916: Android: Fix unfortunate NPE in config check
+* CB-5916: Android: Add "/files/" to persistent files path
+* CB-5915: ios: Update config preference (and docs) to match issue
+* CB-5916: Android: Add config preference for Android persistent storage location
+* iOS: Add config preference for iOS persistent storage location
+* iOS: Android: Allow third-party plugin registration
+* Android: Expose filePlugin getter so that other plugins can register filesystems
+* Fix typos in deprecation message
+* Add backwards-compatibility shim for file-transfer
+* Android: Allow third-party plugin registration
+* CB-5810 [BlackBerry10] resolve local:/// paths (application assets)
+* CB-5774: create DirectoryEntry instead of FileEntry
+* Initial fix for CB-5747
+* Change default FS URL scheme to "cdvfile"
+* Android: Properly format content urls
+* Android, iOS: Replace "filesystem" protocol string with constant
+* Android: Allow absolute paths on Entry.getFile / Entry.getDirectory
+* Android: Make clear that getFile takes a path, not just a filename
+* CB-5008: Rename resolveLocalFileSystemURI to resolveLocalFileSystemURL; deprecate original
+* Remove old file reference from plugin.xml
+* Android: Refactor File API
+* CB-4899 [BlackBerry10] Fix resolve directories
+* CB-5602 Windows8. Fix File Api mobile spec tests
+* Android: Better support for content urls and cross-filesystem copy/move ops
+* CB-5699 [BlackBerry10] Update resolveLocalFileSystemURI implementation
+* CB-5658 Update license comment formatting of doc/index.md
+* CB-5658 Add doc.index.md for File plugin.
+* CB-5658 Delete stale snapshot of plugin docs
+* CB-5403: Backwards-compatibility with file:// urls where possible
+* CB-5407: Fixes for ContentFilesystem
+* Android: Add method for testing backwards-compatibility of filetransfer plugin
+* iOS: Add method for testing backwards-compatiblity of filetransfer plugin
+* Android: Updates to allow FileTransfer to continue to work
+* Android: Clean up unclosed file objects
+* CB-5407: Cleanup
+* CB-5407: Add new Android source files to plugin.xml
+* CB-5407: Move read, write and truncate methods into modules
+* CB-5407: Move copy/move methods into FS modules
+* CB-5407: Move getParent into FS modules
+* CB-5407: Move getmetadata methods into FS modules
+* CB-5407: Move readdir methods into FS modules
+* CB-5407: Move remove methods into FS modules
+* CB-5407: Move getFile into FS modules
+* CB-5407: Start refactoring android code: Modular filesystems, rfs, rlfsurl
+* CB-5407: Update android JS to use FS urls
+* CB-5405: Use URL formatting for Entry.toURL
+* CB-5532 Fix
+* Log file path for File exceptions.
+* Partial fix for iOS File compatibility with previous fileTransfer plugin
+* CB-5532 WP8. Add binary data support to FileWriter
+* CB-5531 WP8. File Api readAsText incorrectly handles position args
+* Added ubuntu platform support
+* Added amazon-fireos platform support
+* CB-5118 [BlackBerry10] Add check for undefined error handler
+* CB-5406: Extend public API for dependent plugins
+* CB-5403: Bump File plugin major version
+* CB-5406: Split iOS file plugin into modules
+* CB-5406: Factor out filesystem providers in iOS
+* CB-5408: Add handler for filesystem:// urls
+* CB-5406: Update iOS native code to use filesystem URLs internally
+* CB-5405: Update JS code to use URLs exclusively
+* CB-4816 Fix file creation outside sandbox for BB10
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6a3bc14a/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 93be870..adeaf44 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.file"
- version="1.0.0-dev">
+ version="1.0.0">
<name>File</name>
<description>Cordova File Plugin</description>
<license>Apache 2.0</license>
[43/50] git commit: CB-5899: Make DirectoryReader.readEntries return
properly formatted Entry objects
Posted by st...@apache.org.
CB-5899: Make DirectoryReader.readEntries return properly formatted Entry objects
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/7e6afafc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/7e6afafc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/7e6afafc
Branch: refs/heads/master
Commit: 7e6afafc3fe64c764d03fa1d64813ec1dd260aa8
Parents: 5e4a875
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jan 29 14:01:12 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jan 29 14:01:12 2014 -0500
----------------------------------------------------------------------
www/DirectoryReader.js | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7e6afafc/www/DirectoryReader.js
----------------------------------------------------------------------
diff --git a/www/DirectoryReader.js b/www/DirectoryReader.js
index af962e8..70f444c 100644
--- a/www/DirectoryReader.js
+++ b/www/DirectoryReader.js
@@ -57,6 +57,7 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback)
entry.isFile = result[i].isFile;
entry.name = result[i].name;
entry.fullPath = result[i].fullPath;
+ entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
retVal.push(entry);
}
reader.hasReadEntries = true;
[22/50] git commit: Android,
iOS: Replace "filesystem" protocol string with constant
Posted by st...@apache.org.
Android, iOS: Replace "filesystem" protocol string with constant
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/2a225e32
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/2a225e32
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/2a225e32
Branch: refs/heads/master
Commit: 2a225e322ea2fac7e45e5348b0aaf2127ca0a2f5
Parents: fc2fc56
Author: Ian Clelland <ic...@chromium.org>
Authored: Sat Jan 11 09:56:48 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Jan 13 10:10:24 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 4 ++--
src/android/LocalFilesystem.java | 2 +-
src/android/LocalFilesystemURL.java | 5 ++++-
src/ios/CDVFile.h | 1 +
src/ios/CDVFile.m | 6 +++---
src/ios/CDVLocalFilesystem.m | 2 +-
www/android/FileSystem.js | 4 +++-
www/ios/FileSystem.js | 4 +++-
8 files changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index b04c901..0a7bf7b 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -702,11 +702,11 @@ public class FileUtils extends CordovaPlugin {
LocalFilesystemURL rootURL;
if (type == TEMPORARY) {
fs.put("name", "temporary");
- rootURL = new LocalFilesystemURL("filesystem://localhost/temporary/");
+ rootURL = new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/temporary/");
}
else if (type == PERSISTENT) {
fs.put("name", "persistent");
- rootURL = new LocalFilesystemURL("filesystem://localhost/persistent/");
+ rootURL = new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL+ "://localhost/persistent/");
}
else {
throw new IOException("No filesystem of type requested");
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index b64118b..171dd9d 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -51,7 +51,7 @@ public class LocalFilesystem extends Filesystem {
public LocalFilesystemURL URLforFilesystemPath(String path) {
String fullPath = this.fullPathForFilesystemPath(path);
if (fullPath != null) {
- return new LocalFilesystemURL("filesystem://localhost/"+this.name+"/"+fullPath);
+ return new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+"/"+fullPath);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index 1065382..a3aade8 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -3,6 +3,9 @@ package org.apache.cordova.file;
import android.net.Uri;
public class LocalFilesystemURL {
+
+ public static final String FILESYSTEM_PROTOCOL = "filesystem";
+
public static final int TEMPORARY = 0;
public static final int PERSISTENT = 1;
@@ -31,7 +34,7 @@ public class LocalFilesystemURL {
}
private int filesystemTypeForLocalURL(Uri URL) {
- if ("filesystem".equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
+ if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
String path = URL.getPath();
if (path != null) {
if (path.startsWith("/temporary")) {
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 1f2c812..0693f68 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -21,6 +21,7 @@
#import <Cordova/CDVPlugin.h>
NSString* const kCDVAssetsLibraryPrefix;
+NSString* const kCDVFilesystemURLPrefix;
enum CDVFileError {
NO_ERROR = 0,
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index e53733d..7bc39b9 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -30,6 +30,8 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
NSString* const NSURLIsExcludedFromBackupKey = @"NSURLIsExcludedFromBackupKey";
#endif
+NSString* const kCDVFilesystemURLPrefix = @"filesystem";
+
@implementation CDVFilesystemURL
@synthesize url=_url;
@synthesize fileSystemType=_fileSystemType;
@@ -62,7 +64,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
*/
- (CDVFileSystemType)filesystemTypeForLocalURI:(NSURL *)uri
{
- if ([[uri scheme] isEqualToString:@"filesystem"] && [[uri host] isEqualToString:@"localhost"]) {
+ if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"]) {
if ([[uri path] hasPrefix:@"/temporary"]) {
return TEMPORARY;
} else if ([[uri path] hasPrefix:@"/persistent"]) {
@@ -106,8 +108,6 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
@implementation CDVFilesystemURLProtocol
-NSString* const kCDVFilesystemURLPrefix = @"filesystem";
-
+ (BOOL)canInitWithRequest:(NSURLRequest*)request
{
NSURL* url = [request URL];
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 6b409c9..5ad2200 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -106,7 +106,7 @@
{
NSString *fullPath = [self fullPathForFileSystemPath:path];
if (fullPath) {
- return [CDVFilesystemURL fileSystemURLWithString:[NSString stringWithFormat:@"filesystem://localhost/%@%@", self.name, fullPath]];
+ return [CDVFilesystemURL fileSystemURLWithString:[NSString stringWithFormat:@"%@://localhost/%@%@", kCDVFilesystemURLPrefix, self.name, fullPath]];
}
return nil;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index 765d4f4..2099a99 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -19,10 +19,12 @@
*
*/
+FILESYSTEM_PROTOCOL = "filesystem";
+
module.exports = {
__format__: function(fullPath) {
var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
- return 'filesystem://localhost' + path;
+ return FILESYSTEM_PROTOCOL + '://localhost' + path;
}
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2a225e32/www/ios/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ios/FileSystem.js b/www/ios/FileSystem.js
index 765d4f4..2099a99 100644
--- a/www/ios/FileSystem.js
+++ b/www/ios/FileSystem.js
@@ -19,10 +19,12 @@
*
*/
+FILESYSTEM_PROTOCOL = "filesystem";
+
module.exports = {
__format__: function(fullPath) {
var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
- return 'filesystem://localhost' + path;
+ return FILESYSTEM_PROTOCOL + '://localhost' + path;
}
};
[36/50] git commit: CB-5915: ios: Update config preference (and docs)
to match issue
Posted by st...@apache.org.
CB-5915: ios: Update config preference (and docs) to match issue
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/40df005f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/40df005f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/40df005f
Branch: refs/heads/master
Commit: 40df005f6d4f3b4a984b3eae0275a16ac8f86513
Parents: 3fa16d0
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 09:54:14 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 09:54:14 2014 -0500
----------------------------------------------------------------------
doc/index.md | 8 +++-----
src/ios/CDVFile.h | 2 ++
src/ios/CDVFile.m | 20 ++++++++++++++------
3 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/40df005f/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 003ba0e..dd36dc7 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -112,18 +112,16 @@ add one of these two lines to config.xml:
<preference name="iosPersistentFileLocation" value="Library" />
- <preference name="iosPersistentFileLocation" value="Documents" />
+ <preference name="iosPersistentFileLocation" value="Compatibility" />
Without this line, the File plugin will not initialize, and your application
will not start.
If your application has previously been shipped to users, using an older (pre-
1.0) version of this plugin, and has stored files in the persistent filesystem,
-then you should set the preference to "Documents". Switching the location to
+then you should set the preference to "Compatibility". Switching the location to
"Library" would mean that existing users who upgrade their application would be
unable to access their previously-stored files.
If your application is new, or has never previously stored files in the
-persistent filesystem, then the "Library" setting is generally recommended,
-unless your application's purpose is to generate document files for users to
-consume externally.
+persistent filesystem, then the "Library" setting is generally recommended.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/40df005f/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 477fad7..751b9d4 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -87,6 +87,7 @@ typedef int CDVFileError;
@end
@interface CDVFile : CDVPlugin {
+ NSString* rootDocsPath;
NSString* appDocsPath;
NSString* appLibraryPath;
NSString* appTempPath;
@@ -136,6 +137,7 @@ typedef int CDVFileError;
/* Internal methods for testing */
- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
+@property (nonatomic, strong) NSString* rootDocsPath;
@property (nonatomic, strong) NSString* appDocsPath;
@property (nonatomic, strong) NSString* appLibraryPath;
@property (nonatomic, strong) NSString* appTempPath;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/40df005f/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index e685929..847f858 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -153,7 +153,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@implementation CDVFile
-@synthesize appDocsPath, appLibraryPath, appTempPath, userHasAllowed, fileSystems=fileSystems_;
+@synthesize rootDocsPath, appDocsPath, appLibraryPath, appTempPath, userHasAllowed, fileSystems=fileSystems_;
- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
[fileSystems_ addObject:fs];
@@ -194,8 +194,8 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSMutableDictionary *settings = vc.settings;
location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString];
NSAssert(
- [location isEqualToString:@"library"] || [location isEqualToString:@"documents"],
- @"File plugin configuration error: Please set ios-persistent-file-location in config.xml to one of \"library\" (for new applications) or \"documents\" (for compatibility with previous versions)");
+ [location isEqualToString:@"library"] || [location isEqualToString:@"compatibility"],
+ @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
}
[self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
@@ -203,7 +203,14 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
[self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
} else {
// Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
- [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appDocsPath]];
+ /*
+ * Fall-back to compatibility mode -- this is the logic implemented in
+ * earlier versions of this plugin, and should be maintained here so
+ * that apps which were originally deployed with older versions of the
+ * plugin can continue to provide access to files stored under those
+ * versions.
+ */
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.rootDocsPath]];
}
[self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
}
@@ -221,14 +228,15 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// Get the Library directory path
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
- self.appLibraryPath = [paths objectAtIndex:0];
+ self.appLibraryPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"files"];
// Get the Temporary directory path
self.appTempPath = [NSTemporaryDirectory()stringByStandardizingPath]; // remove trailing slash from NSTemporaryDirectory()
// Get the Documents directory path
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- self.appDocsPath = [paths objectAtIndex:0];
+ self.rootDocsPath = [paths objectAtIndex:0];
+ self.appDocsPath = [self.rootDocsPath stringByAppendingPathComponent:@"files"];
}
[17/50] git commit: Remove old file reference from plugin.xml
Posted by st...@apache.org.
Remove old file reference from plugin.xml
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/89e6e62d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/89e6e62d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/89e6e62d
Branch: refs/heads/master
Commit: 89e6e62d330a1495dc554e6d0eb45227172e6077
Parents: eaeb598
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Jan 9 14:26:20 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 9 14:26:20 2014 -0500
----------------------------------------------------------------------
plugin.xml | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/89e6e62d/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index dba4dae..e8e6ba6 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -106,7 +106,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<source-file src="src/android/Filesystem.java" target-dir="src/org/apache/cordova/file" />
<source-file src="src/android/LocalFilesystem.java" target-dir="src/org/apache/cordova/file" />
<source-file src="src/android/ContentFilesystem.java" target-dir="src/org/apache/cordova/file" />
- <source-file src="src/android/ReadFileCallback.java" target-dir="src/org/apache/cordova/file" />
<!-- android specific file apis -->
<js-module src="www/android/FileSystem.js" name="androidFileSystem">
[10/50] git commit: CB-5658 Add doc.index.md for File plugin.
Posted by st...@apache.org.
CB-5658 Add doc.index.md for File plugin.
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/9ae13026
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9ae13026
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9ae13026
Branch: refs/heads/master
Commit: 9ae130265c3a1b7a2d4c005347f3c74bf363e197
Parents: c848022
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Dec 18 14:42:31 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 18 14:42:31 2013 -0500
----------------------------------------------------------------------
README.md | 25 ++++++++++++++++++++----
doc/index.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ae13026/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 260c816..9ddc447 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,22 @@
-cordova-plugin-file
---------------------------
-To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
+<!---
+ license: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
-If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html).
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# org.apache.cordova.file
+
+Plugin documentation: [doc/index.md](doc/index.md)
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ae13026/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
new file mode 100644
index 0000000..9044d29
--- /dev/null
+++ b/doc/index.md
@@ -0,0 +1,57 @@
+<!---
+ license: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# org.apache.cordova.file
+
+This plugin provides the [HTML5 Filesystem API](http://dev.w3.org/2009/dap/file-system/pub/FileSystem/). For usage, refer
+to HTML5 Rocks' [FileSystem article](http://www.html5rocks.com/en/tutorials/file/filesystem/)
+on the subject. For an overview of other storage options, refer to Cordova's
+[storage guide](http://cordova.apache.org/docs/en/edge/cordova_storage_storage.md.html).
+
+## Installation
+
+ cordova plugin add org.apache.cordova.file
+
+## Supported Platforms
+
+- Amazon Fire OS
+- Android
+- BlackBerry 10*
+- iOS
+- Windows Phone 7 and 8*
+- Windows 8*
+
+\* _These platforms do not support `FileReader.readAsArrayBuffer` nor `FileWriter.write(blob)`._
+
+## BlackBerry Quirks
+
+`DirectoryEntry.removeRecursively()` may fail with a `ControlledAccessException` in the following cases:
+
+- An app attempts to access a directory created by a previous installation of the app.
+
+> Solution: ensure temporary directories are cleaned manually, or by the application prior to reinstallation.
+
+- If the device is connected by USB.
+
+> Solution: disconnect the USB cable from the device and run again.
+
+## iOS Quirks
+- `FileReader.readAsText(blob, encoding)`
+ - The `encoding` parameter is not supported, and UTF-8 encoding is always in effect.
+
[49/50] git commit: CB-5974: Use safe 'Compatibilty' mode by default
Posted by st...@apache.org.
CB-5974: Use safe 'Compatibilty' mode by default
Only throw an exception and terminate the app on startup if an invalid value
is present in config.xml.
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/3c0ba720
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3c0ba720
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3c0ba720
Branch: refs/heads/master
Commit: 3c0ba7208453f38e7b5d783e5868e892d614bfb3
Parents: d8c5e5d
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Feb 5 16:23:53 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Feb 5 16:23:53 2014 -0500
----------------------------------------------------------------------
doc/index.md | 6 ++++--
src/android/FileUtils.java | 3 +++
src/ios/CDVFile.m | 8 +++++---
3 files changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3c0ba720/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index dd36dc7..b0877c3 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -68,7 +68,8 @@ config.xml:
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
-Without this line, the File plugin will not initialize, and your application
+Without this line, the File plugin will use "Compatibility" as the default. If
+a preference tag is present, and is not one of these values, the application
will not start.
If your application has previously been shipped to users, using an older (pre-
@@ -114,7 +115,8 @@ add one of these two lines to config.xml:
<preference name="iosPersistentFileLocation" value="Compatibility" />
-Without this line, the File plugin will not initialize, and your application
+Without this line, the File plugin will use "Compatibility" as the default. If
+a preference tag is present, and is not one of these values, the application
will not start.
If your application has previously been shipped to users, using an older (pre-
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3c0ba720/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 8e6646b..23496ca 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -104,6 +104,9 @@ public class FileUtils extends CordovaPlugin {
String packageName = activity.getPackageName();
String location = activity.getIntent().getStringExtra("androidpersistentfilelocation");
+ if (location == null) {
+ location = "compatibility";
+ }
if ("internal".equalsIgnoreCase(location)) {
persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
tempRoot = activity.getCacheDir().getAbsolutePath();
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3c0ba720/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index d07cc9c..39234e5 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -193,9 +193,11 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
CDVViewController *vc = (CDVViewController *)_viewController;
NSMutableDictionary *settings = vc.settings;
location = [[settings objectForKey:@"iospersistentfilelocation"] lowercaseString];
- NSAssert(
- [location isEqualToString:@"library"] || [location isEqualToString:@"compatibility"],
- @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
+ }
+ if (location == nil) {
+ // Compatibilty by default (if the config preference is not set, or
+ // if we're not embedded in a CDVViewController somehow.)
+ location = @"compatibility";
}
NSError *error;
[05/50] git commit: Android: Updates to allow FileTransfer to
continue to work
Posted by st...@apache.org.
Android: Updates to allow FileTransfer to continue to work
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/6f52e3b1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/6f52e3b1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/6f52e3b1
Branch: refs/heads/master
Commit: 6f52e3b1e3f4f1f2fd17ea6470df2221b01a65b3
Parents: 6d0dad6
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 15:54:11 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:16:36 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 5 +++
src/android/FileUtils.java | 58 ++++++++++++++++++++++++---------
src/android/Filesystem.java | 3 ++
src/android/LocalFilesystem.java | 23 ++++++++-----
4 files changed, 64 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6f52e3b1/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 17bead8..4e5175b 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -108,4 +108,9 @@ public class ContentFilesystem implements Filesystem {
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
}
+ @Override
+ public String filesystemPathForURL(LocalFilesystemURL url) {
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6f52e3b1/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 00483bc..1f345fe 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.cordova.file;
+import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Base64;
@@ -65,6 +66,9 @@ public class FileUtils extends CordovaPlugin {
public static int PERSISTENT = 1;
public static int RESOURCE = 2;
public static int APPLICATION = 3;
+
+ // This field exists only to support getEntry, below, which has been deprecated
+ private static FileUtils filePlugin;
private interface FileOp {
void run( ) throws Exception;
@@ -94,6 +98,11 @@ public class FileUtils extends CordovaPlugin {
this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
this.filesystems.add(new ContentFilesystem(cordova));
+
+ // Initialize static plugin reference for deprecated getEntry method
+ if (filePlugin == null) {
+ filePlugin = this;
+ }
}
public Filesystem filesystemForURL(LocalFilesystemURL localURL) {
@@ -104,6 +113,20 @@ public class FileUtils extends CordovaPlugin {
}
}
+ @Override
+ public Uri remapUri(Uri uri) {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(uri);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ return null;
+ }
+ return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
/**
* Executes the request and returns whether the action was valid.
*
@@ -644,7 +667,10 @@ public class FileUtils extends CordovaPlugin {
}
/**
- * Returns a JSON object representing the given File.
+ * Returns a JSON object representing the given File. Deprecated, as this is only used by
+ * FileTransfer, and because it is a static method that should really be an instance method,
+ * since it depends on the actual filesystem roots in use. Internal APIs should be modified
+ * to use URLs instead of raw FS paths wherever possible, when interfacing with this plugin.
*
* @param file the File to convert
* @return a JSON representation of the given File
@@ -652,22 +678,22 @@ public class FileUtils extends CordovaPlugin {
*/
@Deprecated
public static JSONObject getEntry(File file) throws JSONException {
- String path = file.getAbsolutePath();
- Boolean isDir = file.isDirectory();
- JSONObject entry = new JSONObject();
-
- int end = path.endsWith("/") ? 1 : 0;
- String[] parts = path.substring(0,path.length()-end).split("/",1);
- String name = parts[parts.length-1];
- entry.put("isFile", !isDir);
- entry.put("isDirectory", isDir);
- entry.put("name", name);
- entry.put("fullPath", path);
- // The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", 0);
+ JSONObject entry;
- return entry;
+ if (filePlugin != null) {
+ LocalFilesystem fs;
+ fs = (LocalFilesystem) filePlugin.filesystems.get(0);
+ entry = fs.makeEntryForFile(file, 0);
+ if (entry != null) {
+ return entry;
+ }
+ fs = (LocalFilesystem) filePlugin.filesystems.get(1);
+ entry = fs.makeEntryForFile(file, 1);
+ if (entry != null) {
+ return entry;
+ }
+ }
+ return null;
}
/**
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6f52e3b1/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 6955520..57e1794 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -37,4 +37,7 @@ public interface Filesystem {
long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
throws IOException, NoModificationAllowedException;
+ // This method should return null if filesystem urls cannot be mapped to paths
+ String filesystemPathForURL(LocalFilesystemURL url);
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6f52e3b1/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index be1d2d1..755a802 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -30,6 +30,7 @@ public class LocalFilesystem implements Filesystem {
this.cordova = cordova;
}
+ @Override
public String filesystemPathForURL(LocalFilesystemURL url) {
String path = this.fsRoot + url.fullPath;
if (path.endsWith("/")) {
@@ -37,7 +38,14 @@ public class LocalFilesystem implements Filesystem {
}
return path;
}
-
+
+ private String fullPathForFilesystemPath(String absolutePath) {
+ if (absolutePath != null && absolutePath.startsWith(this.fsRoot)) {
+ return absolutePath.substring(this.fsRoot.length());
+ }
+ return null;
+ }
+
public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
JSONObject entry = new JSONObject();
@@ -57,7 +65,11 @@ public class LocalFilesystem implements Filesystem {
}
public JSONObject makeEntryForFile(File file, int fsType) throws JSONException {
- return makeEntryForPath(this.fullPathForFilesystemPath(file.getAbsolutePath()), fsType, file.isDirectory());
+ String path = this.fullPathForFilesystemPath(file.getAbsolutePath());
+ if (path != null) {
+ return makeEntryForPath(path, fsType, file.isDirectory());
+ }
+ return null;
}
@Override
@@ -199,13 +211,6 @@ public class LocalFilesystem implements Filesystem {
return entries;
}
- private String fullPathForFilesystemPath(String absolutePath) {
- if (absolutePath != null && absolutePath.startsWith(this.fsRoot)) {
- return absolutePath.substring(this.fsRoot.length());
- }
- return null;
- }
-
@Override
public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
File file = new File(filesystemPathForURL(inputURL));
[25/50] git commit: CB-5774: create DirectoryEntry instead of
FileEntry
Posted by st...@apache.org.
CB-5774: create DirectoryEntry instead of FileEntry
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/9b290353
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9b290353
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9b290353
Branch: refs/heads/master
Commit: 9b290353eca2bd64e5deabbb75487052281100ea
Parents: 3e4f9cd
Author: Matti Eerola <ma...@softapalvelin.com>
Authored: Wed Jan 15 22:07:46 2014 +0200
Committer: Matti Eerola <ma...@softapalvelin.com>
Committed: Wed Jan 15 22:07:46 2014 +0200
----------------------------------------------------------------------
src/windows8/FileProxy.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9b290353/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 4a20c64..af5aab8 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -431,7 +431,7 @@ module.exports = {
promiseArr[index++] = storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
if (folderList !== null) {
for (var j = 0; j < folderList.length; j++) {
- result.push(new FileEntry(folderList[j].name, folderList[j].path));
+ result.push(new DirectoryEntry(folderList[j].name, folderList[j].path));
}
}
});
[07/50] git commit: Android: Add method for testing
backwards-compatibility of filetransfer plugin
Posted by st...@apache.org.
Android: Add method for testing backwards-compatibility of filetransfer plugin
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/83a867cc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/83a867cc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/83a867cc
Branch: refs/heads/master
Commit: 83a867cc7811fa2b0aff5f340c8a1122ee40e6e2
Parents: 4c44780
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Dec 11 11:26:32 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:16:37 2013 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/83a867cc/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 1f345fe..7e852b5 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -361,12 +361,38 @@ public class FileUtils extends CordovaPlugin {
}
},callbackContext);
}
+ else if (action.equals("_getLocalFilesystemPath")) {
+ // Internal method for testing: Get the on-disk location of a local filesystem url.
+ // [Currently used for testing file-transfer]
+ final String localURLstr = args.getString(0);
+ threadhelper( new FileOp( ){
+ public void run() throws FileNotFoundException, JSONException, MalformedURLException {
+ String fname = _filesystemPathForURL(localURLstr);
+ callbackContext.success(fname);
+ }
+ },callbackContext);
+ }
else {
return false;
}
return true;
}
+ /* Internal method for testing: Get the on-disk location of a local filesystem url.
+ */
+ protected String _filesystemPathForURL(String localURLstr) throws MalformedURLException {
+ try {
+ LocalFilesystemURL inputURL = new LocalFilesystemURL(localURLstr);
+ Filesystem fs = this.filesystemForURL(inputURL);
+ if (fs == null) {
+ throw new MalformedURLException("No installed handlers for this URL");
+ }
+ return fs.filesystemPathForURL(inputURL);
+ } catch (IllegalArgumentException e) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
+ }
+ }
+
/* helper to execute functions async and handle the result codes
*
*/
[04/50] git commit: Android: Clean up unclosed file objects
Posted by st...@apache.org.
Android: Clean up unclosed file objects
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/6d0dad63
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/6d0dad63
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/6d0dad63
Branch: refs/heads/master
Commit: 6d0dad633e4a62c3043604ead3566f31d74ae335
Parents: 0a6adf0
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Dec 2 15:53:43 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:16:36 2013 -0500
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6d0dad63/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index adb3ef6..be1d2d1 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -537,19 +537,20 @@ public class LocalFilesystem implements Filesystem {
String contentType;
File file = new File(this.filesystemPathForURL(inputURL));
- InputStream inputStream = new FileInputStream(file);
-
contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+
+ InputStream inputStream = new FileInputStream(file);
int numBytesRead = 0;
-
- if (start > 0) {
- inputStream.skip(start);
- }
-
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ try {
+ if (start > 0) {
+ inputStream.skip(start);
+ }
+ while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
+ numBytesToRead -= numBytesRead;
+ }
+ } finally {
+ inputStream.close();
}
- inputStream.close();
readFileCallback.handleData(bytes, contentType);
}
@@ -572,12 +573,16 @@ public class LocalFilesystem implements Filesystem {
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
try
{
+ byte buff[] = new byte[rawData.length];
FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append);
- byte buff[] = new byte[rawData.length];
- in.read(buff, 0, buff.length);
- out.write(buff, 0, rawData.length);
- out.flush();
- out.close();
+ try {
+ in.read(buff, 0, buff.length);
+ out.write(buff, 0, rawData.length);
+ out.flush();
+ } finally {
+ // Always close the output
+ out.close();
+ }
}
catch (NullPointerException e)
{
[08/50] git commit: CB-5403: Backwards-compatibility with file://
urls where possible
Posted by st...@apache.org.
CB-5403: Backwards-compatibility with file:// urls where possible
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/eb28b7a2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/eb28b7a2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/eb28b7a2
Branch: refs/heads/master
Commit: eb28b7a29dff03b86802a9f2d4b5f8fd304977dc
Parents: a2b9073
Author: Ian Clelland <ic...@chromium.org>
Authored: Sun Dec 15 23:35:34 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Dec 16 00:24:39 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 6 ++++++
src/android/FileUtils.java | 35 +++++++++++++++++++++++++++++++--
src/android/Filesystem.java | 2 ++
src/android/LocalFilesystem.java | 9 +++++++++
src/ios/CDVFile.m | 20 +++++++++++++++++--
www/android/FileSystem.js | 3 ++-
www/ios/FileSystem.js | 3 ++-
7 files changed, 72 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index b1d397e..e19f5bc 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -129,4 +129,10 @@ public class ContentFilesystem implements Filesystem {
}
return null;
}
+
+ @Override
+ public LocalFilesystemURL URLforFilesystemPath(String path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 1ae7d0c..25ea6b4 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -398,7 +398,20 @@ public class FileUtils extends CordovaPlugin {
}
}
- /* helper to execute functions async and handle the result codes
+ protected LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
+ LocalFilesystemURL localURL;
+ for (Filesystem fs: filesystems) {
+ if (fs != null) {
+ localURL = fs.URLforFilesystemPath(localPath);
+ if (localURL != null)
+ return localURL;
+ }
+ }
+ return null;
+ }
+
+
+ /* helper to execute functions async and handle the result codes
*
*/
private void threadhelper(final FileOp f, final CallbackContext callbackContext){
@@ -462,9 +475,27 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
String decoded = URLDecoder.decode(url, "UTF-8");
+ LocalFilesystemURL inputURL;
+ if (url == null) {
+ throw new MalformedURLException("Unrecognized filesystem URL");
+ }
+
+ /* Backwards-compatibility: Check for file:// urls */
+ if (decoded.startsWith("file://")) {
+ /* This looks like a file url. Get the path, and see if any handlers recognize it. */
+ String path;
+ int questionMark = decoded.indexOf("?");
+ if (questionMark < 0) {
+ path = decoded.substring(7, decoded.length());
+ } else {
+ path = decoded.substring(7, questionMark);
+ }
+ inputURL = this.filesystemURLforLocalPath(path);
+ } else {
+ inputURL = new LocalFilesystemURL(decoded);
+ }
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(decoded);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 57e1794..7dd99f2 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -40,4 +40,6 @@ public interface Filesystem {
// This method should return null if filesystem urls cannot be mapped to paths
String filesystemPathForURL(LocalFilesystemURL url);
+ LocalFilesystemURL URLforFilesystemPath(String path);
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 755a802..6634661 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -46,6 +46,15 @@ public class LocalFilesystem implements Filesystem {
return null;
}
+ @Override
+ public LocalFilesystemURL URLforFilesystemPath(String path) {
+ String fullPath = this.fullPathForFilesystemPath(path);
+ if (fullPath != null) {
+ return new LocalFilesystemURL("filesystem://localhost/"+this.name+"/"+fullPath);
+ }
+ return null;
+ }
+
public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
JSONObject entry = new JSONObject();
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 517e349..e53733d 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -323,9 +323,25 @@ NSString* const kCDVFilesystemURLPrefix = @"filesystem";
- (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command
{
// arguments
- CDVFilesystemURL* inputURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments objectAtIndex:0]];
+ NSString* localURIstr = [command.arguments objectAtIndex:0];
CDVPluginResult* result;
- if (inputURI.fileSystemType == -1) {
+ CDVFilesystemURL* inputURI;
+
+ /* Backwards-compatibility: Check for file:// urls */
+ if ([localURIstr hasPrefix:@"file://"]) {
+ /* This looks like a file url. Get the path, and see if any handlers recognize it. */
+ NSString* path;
+ NSRange questionMark = [localURIstr rangeOfString:@"?"];
+ if (questionMark.location == NSNotFound) {
+ path = [localURIstr substringFromIndex:7];
+ } else {
+ path = [localURIstr substringWithRange:NSMakeRange(7,questionMark.location-7)];
+ }
+ inputURI = [self fileSystemURLforLocalPath:path];
+ } else {
+ inputURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
+ }
+ if (inputURI != nil && inputURI.fileSystemType == -1) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ENCODING_ERR];
} else {
CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:inputURI.fileSystemType];
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index 2017e29..765d4f4 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -21,7 +21,8 @@
module.exports = {
__format__: function(fullPath) {
- return 'filesystem://localhost/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath);
+ var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+ return 'filesystem://localhost' + path;
}
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/www/ios/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ios/FileSystem.js b/www/ios/FileSystem.js
index 2017e29..765d4f4 100644
--- a/www/ios/FileSystem.js
+++ b/www/ios/FileSystem.js
@@ -21,7 +21,8 @@
module.exports = {
__format__: function(fullPath) {
- return 'filesystem://localhost/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath);
+ var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+ return 'filesystem://localhost' + path;
}
};
[26/50] git commit: Merge
https://github.com/spMatti/cordova-plugin-file into dev
Posted by st...@apache.org.
Merge https://github.com/spMatti/cordova-plugin-file into dev
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/54a8e7de
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/54a8e7de
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/54a8e7de
Branch: refs/heads/master
Commit: 54a8e7de65fe9c1ff7e9194e7ada8964338fad3d
Parents: 9d52816 9b29035
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Jan 15 14:31:19 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Jan 15 14:31:19 2014 -0800
----------------------------------------------------------------------
src/windows8/FileProxy.js | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/54a8e7de/src/windows8/FileProxy.js
----------------------------------------------------------------------
[47/50] git commit: CB-5974: Android: Don't allow File operations to
continue when not configured
Posted by st...@apache.org.
CB-5974: Android: Don't allow File operations to continue when not configured
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/f4ed88d8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/f4ed88d8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/f4ed88d8
Branch: refs/heads/master
Commit: f4ed88d8da9944fbd7863bf03b276dd03c98daad
Parents: 4ce92df
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Feb 5 00:03:03 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Feb 5 00:03:03 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/f4ed88d8/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index cc5e8c0..26e3479 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -66,6 +66,8 @@ public class FileUtils extends CordovaPlugin {
public static int UNKNOWN_ERR = 1000;
+ private boolean configured = false;
+
// This field exists only to support getEntry, below, which has been deprecated
private static FileUtils filePlugin;
@@ -139,6 +141,8 @@ public class FileUtils extends CordovaPlugin {
this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
+ this.configured = true;
+
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
FileUtils.filePlugin = this;
@@ -182,6 +186,10 @@ public class FileUtils extends CordovaPlugin {
* @return True if the action was valid, false otherwise.
*/
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ if (!configured) {
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "File plugin is not configured. Please see the README.md file for details on how to update config.xml"));
+ return true;
+ }
if (action.equals("testSaveLocationExists")) {
threadhelper( new FileOp( ){
public void run() {
[48/50] git commit: CB-5915: CB-5916: Reorganize preference code to
make defaults possible
Posted by st...@apache.org.
CB-5915: CB-5916: Reorganize preference code to make defaults possible
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/d8c5e5dc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/d8c5e5dc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/d8c5e5dc
Branch: refs/heads/master
Commit: d8c5e5dc8063658c863d4f5f13e18fdcf6383804
Parents: f4ed88d
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Feb 5 16:23:39 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Feb 5 16:23:39 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 49 +++++++++++++++++++++--------------------
src/ios/CDVFile.m | 6 +++--
2 files changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8c5e5dc/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 26e3479..8e6646b 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -104,31 +104,30 @@ public class FileUtils extends CordovaPlugin {
String packageName = activity.getPackageName();
String location = activity.getIntent().getStringExtra("androidpersistentfilelocation");
- if (location == null || !(location.equalsIgnoreCase("internal") || location.equalsIgnoreCase("compatibility"))) {
- Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
- activity.finish();
- }
- else {
- if (location.equalsIgnoreCase("internal")) {
- persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
- tempRoot = activity.getCacheDir().getAbsolutePath();
+ if ("internal".equalsIgnoreCase(location)) {
+ persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
+ tempRoot = activity.getCacheDir().getAbsolutePath();
+ this.configured = true;
+ } else if ("compatibility".equalsIgnoreCase(location)) {
+ /*
+ * Fall-back to compatibility mode -- this is the logic implemented in
+ * earlier versions of this plugin, and should be maintained here so
+ * that apps which were originally deployed with older versions of the
+ * plugin can continue to provide access to files stored under those
+ * versions.
+ */
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
+ tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
+ "/Android/data/" + packageName + "/cache/";
} else {
- /*
- * Fall-back to compatibility mode -- this is the logic implemented in
- * earlier versions of this plugin, and should be maintained here so
- * that apps which were originally deployed with older versions of the
- * plugin can continue to provide access to files stored under those
- * versions.
- */
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
- tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + packageName + "/cache/";
- } else {
- persistentRoot = "/data/data/" + packageName;
- tempRoot = "/data/data/" + packageName + "/cache/";
- }
+ persistentRoot = "/data/data/" + packageName;
+ tempRoot = "/data/data/" + packageName + "/cache/";
}
+ this.configured = true;
+ }
+
+ if (this.configured) {
// Create the directories if they don't exist.
new File(tempRoot).mkdirs();
new File(persistentRoot).mkdirs();
@@ -141,12 +140,14 @@ public class FileUtils extends CordovaPlugin {
this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
- this.configured = true;
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
FileUtils.filePlugin = this;
}
+ } else {
+ Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
+ activity.finish();
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8c5e5dc/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index b1925d0..d07cc9c 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -216,8 +216,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
} else {
NSLog(@"Unable to create library directory: %@", error);
}
- } else {
- // Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
+ } else if ([location isEqualToString:@"compatibility"]) {
/*
* Fall-back to compatibility mode -- this is the logic implemented in
* earlier versions of this plugin, and should be maintained here so
@@ -226,6 +225,9 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
* versions.
*/
[self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.rootDocsPath]];
+ } else {
+ NSAssert(false,
+ @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
}
[self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
}
[19/50] git commit: CB-5008: Rename resolveLocalFileSystemURI to
resolveLocalFileSystemURL; deprecate original
Posted by st...@apache.org.
CB-5008: Rename resolveLocalFileSystemURI to resolveLocalFileSystemURL; deprecate original
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/9ec003a0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9ec003a0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9ec003a0
Branch: refs/heads/master
Commit: 9ec003a0a5678db1a54aacf74d0db416a2833803
Parents: 89e6e62
Author: Ian Clelland <ic...@chromium.org>
Authored: Sat Jan 11 09:43:08 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Sat Jan 11 09:43:08 2014 -0500
----------------------------------------------------------------------
plugin.xml | 2 +-
www/resolveLocalFileSystemURI.js | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ec003a0/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index e8e6ba6..f5d215a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -79,7 +79,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
</js-module>
<js-module src="www/resolveLocalFileSystemURI.js" name="resolveLocalFileSystemURI">
- <clobbers target="window.resolveLocalFileSystemURI" />
+ <merges target="window" />
</js-module>
<!-- android -->
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ec003a0/www/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/resolveLocalFileSystemURI.js b/www/resolveLocalFileSystemURI.js
index 8bfbfe2..3d3b1dc 100644
--- a/www/resolveLocalFileSystemURI.js
+++ b/www/resolveLocalFileSystemURI.js
@@ -31,7 +31,7 @@ var argscheck = require('cordova/argscheck'),
* @param successCallback invoked with Entry object corresponding to URI
* @param errorCallback invoked if error occurs retrieving file system entry
*/
-module.exports = function(uri, successCallback, errorCallback) {
+module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorCallback) {
argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
// error callback
var fail = function(error) {
@@ -63,3 +63,7 @@ module.exports = function(uri, successCallback, errorCallback) {
exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
};
+module.exports.resolveLocalFileSystemURI = function() {
+ console.log("resolveLocalfileSystemURI is deprecated. Please call reolvelLocalFileSystemURL instead");
+ module.exports.resolveLocalFileSystemURL.apply(this, arguments);
+};
[29/50] git commit: Android: Allow third-party plugin registration
Posted by st...@apache.org.
Android: Allow third-party plugin registration
This change decouples the specific order and names of filesystem
instances from the FileUtils and LocalFilesystemURL classes.
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/5268af33
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5268af33
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5268af33
Branch: refs/heads/master
Commit: 5268af336861c2c288e7fabad7aa1967556c8d8a
Parents: 3fe44cf
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 21 14:32:00 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 23 09:00:54 2014 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 7 +--
src/android/FileUtils.java | 81 ++++++++++++++++----------------
src/android/Filesystem.java | 22 ++++++---
src/android/LocalFilesystem.java | 47 +++++++++---------
src/android/LocalFilesystemURL.java | 38 ++++++---------
www/resolveLocalFileSystemURI.js | 6 +--
6 files changed, 103 insertions(+), 98 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 535a2fe..f116b31 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -22,7 +22,8 @@ public class ContentFilesystem extends Filesystem {
private CordovaInterface cordova;
private CordovaResourceApi resourceApi;
- public ContentFilesystem(CordovaInterface cordova, CordovaWebView webView) {
+ public ContentFilesystem(String name, CordovaInterface cordova, CordovaWebView webView) {
+ this.name = name;
this.cordova = cordova;
this.resourceApi = new CordovaResourceApi(webView.getContext(), webView.pluginManager);
}
@@ -45,7 +46,7 @@ public class ContentFilesystem extends Filesystem {
throw new IOException();
}
try {
- return makeEntryForPath(inputURL.fullPath, inputURL.filesystemType, fp.isDirectory());
+ return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, fp.isDirectory());
} catch (JSONException e) {
throw new IOException();
}
@@ -74,7 +75,7 @@ public class ContentFilesystem extends Filesystem {
}
}
// Return the directory
- return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemType, directory);
+ return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemName, directory);
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 0a7bf7b..cfefd53 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -64,12 +64,6 @@ public class FileUtils extends CordovaPlugin {
public static int PATH_EXISTS_ERR = 12;
public static int UNKNOWN_ERR = 1000;
-
- public static int TEMPORARY = 0;
- public static int PERSISTENT = 1;
- public static int RESOURCE = 2;
- public static int APPLICATION = 3;
- public static int CONTENT = 4;
// This field exists only to support getEntry, below, which has been deprecated
private static FileUtils filePlugin;
@@ -80,6 +74,21 @@ public class FileUtils extends CordovaPlugin {
private ArrayList<Filesystem> filesystems;
+ public void registerFilesystem(Filesystem fs) {
+ if (fs != null && filesystemForName(fs.name)== null) {
+ this.filesystems.add(fs);
+ }
+ }
+
+ private Filesystem filesystemForName(String name) {
+ for (Filesystem fs:filesystems) {
+ if (fs != null && fs.name != null && fs.name.equals(name)) {
+ return fs;
+ }
+ }
+ return null;
+ }
+
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
@@ -99,11 +108,14 @@ public class FileUtils extends CordovaPlugin {
// Create the cache dir if it doesn't exist.
fp = new File(tempRoot);
fp.mkdirs();
- this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
- this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
- this.filesystems.add(null); // Hold for 'resource' FS
- this.filesystems.add(null); // Hold for 'application' FS
- this.filesystems.add(new ContentFilesystem(cordova, webView));
+
+ // Register initial filesystems
+ // Note: The temporary and persistent filesystems need to be the first two
+ // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
+ // per spec.
+ this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot));
+ this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
+ this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
@@ -111,12 +123,9 @@ public class FileUtils extends CordovaPlugin {
}
}
- public Filesystem filesystemForURL(LocalFilesystemURL localURL) {
- try {
- return this.filesystems.get(localURL.filesystemType);
- } catch (ArrayIndexOutOfBoundsException e) {
- return null;
- }
+ private Filesystem filesystemForURL(LocalFilesystemURL localURL) {
+ if (localURL == null) return null;
+ return filesystemForName(localURL.filesystemName);
}
@Override
@@ -699,20 +708,17 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject requestFileSystem(int type) throws IOException, JSONException {
JSONObject fs = new JSONObject();
- LocalFilesystemURL rootURL;
- if (type == TEMPORARY) {
- fs.put("name", "temporary");
- rootURL = new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/temporary/");
- }
- else if (type == PERSISTENT) {
- fs.put("name", "persistent");
- rootURL = new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL+ "://localhost/persistent/");
+ Filesystem rootFs = null;
+ try {
+ rootFs = this.filesystems.get(type);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // Pass null through
}
- else {
- throw new IOException("No filesystem of type requested");
+ if (rootFs == null) {
+ throw new IOException("No filesystem of type requested");
}
- Filesystem rootFs = this.filesystemForURL(rootURL);
- fs.put("root", rootFs.getEntryForLocalURL(rootURL));
+ fs.put("name", rootFs.name);
+ fs.put("root", Filesystem.makeEntryForPath("/", rootFs.name, true));
return fs;
}
@@ -730,18 +736,13 @@ public class FileUtils extends CordovaPlugin {
public static JSONObject getEntry(File file) throws JSONException {
JSONObject entry;
- if (filePlugin != null) {
- LocalFilesystem fs;
- fs = (LocalFilesystem) filePlugin.filesystems.get(0);
- entry = fs.makeEntryForFile(file, 0);
- if (entry != null) {
- return entry;
+ if (filePlugin != null) {
+ for (Filesystem fs:filePlugin.filesystems) {
+ entry = fs.makeEntryForFile(file);
+ if (entry != null) {
+ return entry;
+ }
}
- fs = (LocalFilesystem) filePlugin.filesystems.get(1);
- entry = fs.makeEntryForFile(file, 1);
- if (entry != null) {
- return entry;
- }
}
return null;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 6aa5860..560cc85 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -1,5 +1,6 @@
package org.apache.cordova.file;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
@@ -12,31 +13,33 @@ import org.json.JSONObject;
public abstract class Filesystem {
+ public String name;
+
public interface ReadFileCallback {
public void handleData(InputStream inputStream, String contentType) throws IOException;
}
- public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir)
+ public static JSONObject makeEntryForPath(String path, String fsName, Boolean isDir)
throws JSONException {
JSONObject entry = new JSONObject();
int end = path.endsWith("/") ? 1 : 0;
String[] parts = path.substring(0,path.length()-end).split("/");
- String name = parts[parts.length-1];
+ String fileName = parts[parts.length-1];
entry.put("isFile", !isDir);
entry.put("isDirectory", isDir);
- entry.put("name", name);
+ entry.put("name", fileName);
entry.put("fullPath", path);
// The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", fsType);
+ // but the filesystem name can be.
+ entry.put("filesystemName", fsName);
return entry;
}
public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir) throws JSONException {
- return makeEntryForPath(inputURL.fullPath, inputURL.filesystemType, isDir);
+ return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, isDir);
}
abstract JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
@@ -171,4 +174,11 @@ public abstract class Filesystem {
}
}
+ /* Create a FileEntry or DirectoryEntry given an actual file on device.
+ * Return null if the file does not exist within this filesystem.
+ */
+ public JSONObject makeEntryForFile(File file) throws JSONException {
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 171dd9d..0e46d1e 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -21,11 +21,10 @@ import android.net.Uri;
public class LocalFilesystem extends Filesystem {
- private String name;
private String fsRoot;
private CordovaInterface cordova;
- public LocalFilesystem(CordovaInterface cordova, String name, String fsRoot) {
+ public LocalFilesystem(String name, CordovaInterface cordova, String fsRoot) {
this.name = name;
this.fsRoot = fsRoot;
this.cordova = cordova;
@@ -56,10 +55,11 @@ public class LocalFilesystem extends Filesystem {
return null;
}
- public JSONObject makeEntryForFile(File file, int fsType) throws JSONException {
+ @Override
+ public JSONObject makeEntryForFile(File file) throws JSONException {
String path = this.fullPathForFilesystemPath(file.getAbsolutePath());
if (path != null) {
- return makeEntryForPath(path, fsType, file.isDirectory());
+ return makeEntryForPath(path, this.name, file.isDirectory());
}
return null;
}
@@ -81,8 +81,9 @@ public class LocalFilesystem extends Filesystem {
entry.put("name", fp.getName());
entry.put("fullPath", inputURL.fullPath);
// The file system can't be specified, as it would lead to an infinite loop.
- // But we can specify the type of FS, and the rest can be reconstructed in JS.
- entry.put("filesystem", inputURL.filesystemType);
+ // But we can specify the name of the FS, and the rest can be reconstructed
+ // in JS.
+ entry.put("filesystemName", inputURL.filesystemName);
return entry;
} catch (JSONException e) {
throw new IOException();
@@ -147,7 +148,7 @@ public class LocalFilesystem extends Filesystem {
}
// Return the directory
- return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemType, directory);
+ return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemName, directory);
}
@Override
@@ -199,7 +200,7 @@ public class LocalFilesystem extends Filesystem {
for (int i = 0; i < files.length; i++) {
if (files[i].canRead()) {
try {
- entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()), inputURL.filesystemType, files[i].isDirectory()));
+ entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()), inputURL.filesystemName, files[i].isDirectory()));
} catch (JSONException e) {
}
}
@@ -260,7 +261,7 @@ public class LocalFilesystem extends Filesystem {
* @throws InvalidModificationException
* @throws JSONException
*/
- private JSONObject copyFile(File srcFile, File destFile, int fsType) throws IOException, InvalidModificationException, JSONException {
+ private JSONObject copyFile(File srcFile, File destFile) throws IOException, InvalidModificationException, JSONException {
// 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");
@@ -268,7 +269,7 @@ public class LocalFilesystem extends Filesystem {
copyAction(srcFile, destFile);
- return makeEntryForFile(destFile, fsType);
+ return makeEntryForFile(destFile);
}
/**
@@ -302,7 +303,7 @@ public class LocalFilesystem extends Filesystem {
* @throws NoModificationAllowedException
* @throws InvalidModificationException
*/
- private JSONObject copyDirectory(File srcDir, File destinationDir, int fsType) throws JSONException, IOException, NoModificationAllowedException, InvalidModificationException {
+ private JSONObject copyDirectory(File srcDir, File destinationDir) throws JSONException, IOException, NoModificationAllowedException, InvalidModificationException {
// 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");
@@ -325,13 +326,13 @@ public class LocalFilesystem extends Filesystem {
for (File file : srcDir.listFiles()) {
File destination = new File(destinationDir.getAbsoluteFile() + File.separator + file.getName());
if (file.isDirectory()) {
- copyDirectory(file, destination, fsType);
+ copyDirectory(file, destination);
} else {
- copyFile(file, destination, fsType);
+ copyFile(file, destination);
}
}
- return makeEntryForFile(destinationDir, fsType);
+ return makeEntryForFile(destinationDir);
}
/**
@@ -344,7 +345,7 @@ public class LocalFilesystem extends Filesystem {
* @throws InvalidModificationException
* @throws JSONException
*/
- private JSONObject moveFile(File srcFile, File destFile, int fsType) throws IOException, 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");
@@ -364,7 +365,7 @@ public class LocalFilesystem extends Filesystem {
}
}
- return makeEntryForFile(destFile, fsType);
+ return makeEntryForFile(destFile);
}
/**
@@ -379,7 +380,7 @@ public class LocalFilesystem extends Filesystem {
* @throws NoModificationAllowedException
* @throws FileExistsException
*/
- private JSONObject moveDirectory(File srcDir, File destinationDir, int fsType) throws IOException, JSONException, InvalidModificationException, NoModificationAllowedException, FileExistsException {
+ 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");
@@ -403,7 +404,7 @@ public class LocalFilesystem extends Filesystem {
// Now we have to do things the hard way
// 1) Copy all the old files
// 2) delete the src directory
- copyDirectory(srcDir, destinationDir, fsType);
+ copyDirectory(srcDir, destinationDir);
if (destinationDir.exists()) {
removeDirRecursively(srcDir);
} else {
@@ -411,7 +412,7 @@ public class LocalFilesystem extends Filesystem {
}
}
- return makeEntryForFile(destinationDir, fsType);
+ return makeEntryForFile(destinationDir);
}
@Override
@@ -449,15 +450,15 @@ public class LocalFilesystem extends Filesystem {
if (sourceFile.isDirectory()) {
if (move) {
- return moveDirectory(sourceFile, destinationFile, destURL.filesystemType);
+ return moveDirectory(sourceFile, destinationFile);
} else {
- return copyDirectory(sourceFile, destinationFile, destURL.filesystemType);
+ return copyDirectory(sourceFile, destinationFile);
}
} else {
if (move) {
- return moveFile(sourceFile, destinationFile, destURL.filesystemType);
+ return moveFile(sourceFile, destinationFile);
} else {
- return copyFile(sourceFile, destinationFile, destURL.filesystemType);
+ return copyFile(sourceFile, destinationFile);
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index 2aec395..808fc20 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -1,52 +1,44 @@
package org.apache.cordova.file;
+import java.util.List;
+
import android.net.Uri;
public class LocalFilesystemURL {
public static final String FILESYSTEM_PROTOCOL = "cdvfile";
- public static final int TEMPORARY = 0;
- public static final int PERSISTENT = 1;
-
Uri URL;
- int filesystemType;
+ String filesystemName;
String fullPath;
public LocalFilesystemURL(Uri URL) {
this.URL = URL;
- this.filesystemType = this.filesystemTypeForLocalURL(URL);
+ this.filesystemName = this.filesystemNameForLocalURL(URL);
this.fullPath = this.fullPathForLocalURL(URL);
}
private String fullPathForLocalURL(Uri URL) {
- int fsType = this.filesystemTypeForLocalURL(URL);
- if (fsType == FileUtils.TEMPORARY) {
- return URL.getPath().substring(10);
- }
- if (fsType == FileUtils.PERSISTENT) {
- return URL.getPath().substring(11);
- }
- if (fsType == FileUtils.CONTENT) {
+ if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
+ String path = URL.getPath();
+ return path.substring(path.indexOf('/', 1));
+ } else if ("content".equals(URL.getScheme())) {
return '/' + URL.getHost() + URL.getPath();
}
return null;
}
- private int filesystemTypeForLocalURL(Uri URL) {
+ private String filesystemNameForLocalURL(Uri URL) {
if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
- String path = URL.getPath();
- if (path != null) {
- if (path.startsWith("/temporary")) {
- return FileUtils.TEMPORARY;
- } else if (path.startsWith("/persistent")) {
- return FileUtils.PERSISTENT;
- }
+ List<String> pathComponents = URL.getPathSegments();
+ if (pathComponents != null && pathComponents.size() > 0) {
+ return pathComponents.get(0);
}
+ return null;
} else if ("content".equals(URL.getScheme())) {
- return FileUtils.CONTENT;
+ return "content";
}
- return -1;
+ return null;
}
public LocalFilesystemURL(String strURL) {
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5268af33/www/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/resolveLocalFileSystemURI.js b/www/resolveLocalFileSystemURI.js
index 3d3b1dc..06090c2 100644
--- a/www/resolveLocalFileSystemURI.js
+++ b/www/resolveLocalFileSystemURI.js
@@ -46,12 +46,12 @@ module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorC
}
// if successful, return either a file or directory entry
var success = function(entry) {
- var result;
if (entry) {
if (successCallback) {
// create appropriate Entry object
- fs = new FileSystem(entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
- result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs) : new FileEntry(entry.name, entry.fullPath, fs);
+ var fsName = entry.filesystemName || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
+ var fs = new FileSystem(fsName);
+ var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs) : new FileEntry(entry.name, entry.fullPath, fs);
successCallback(result);
}
}
[46/50] git commit: CB-5960: ios: android: Properly handle parent
references in getFile/getDirectory
Posted by st...@apache.org.
CB-5960: ios: android: Properly handle parent references in getFile/getDirectory
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/4ce92dff
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/4ce92dff
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/4ce92dff
Branch: refs/heads/master
Commit: 4ce92dff1b554b0a5d3a5e88bac2cf019f9266ae
Parents: e3d9ac1
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Jan 31 16:58:05 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Jan 31 16:58:05 2014 -0500
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 48 ++++++++++++++++++++++++++++++---
src/ios/CDVLocalFilesystem.m | 50 ++++++++++++++++++++++++++++++-----
2 files changed, 88 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4ce92dff/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index ebcbaec..762f80b 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -10,6 +10,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Arrays;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
@@ -46,15 +48,53 @@ public class LocalFilesystem extends Filesystem {
return null;
}
- @Override
- public LocalFilesystemURL URLforFilesystemPath(String path) {
- String fullPath = this.fullPathForFilesystemPath(path);
+ protected LocalFilesystemURL URLforFullPath(String fullPath) {
if (fullPath != null) {
+ if (fullPath.startsWith("/")) {
+ return new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+fullPath);
+ }
return new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+"/"+fullPath);
}
return null;
+
+ }
+
+ @Override
+ public LocalFilesystemURL URLforFilesystemPath(String path) {
+ return this.URLforFullPath(this.fullPathForFilesystemPath(path));
}
+ protected String normalizePath(String rawPath) {
+ // If this is an absolute path, trim the leading "/" and replace it later
+ boolean isAbsolutePath = rawPath.startsWith("/");
+ if (isAbsolutePath) {
+ rawPath = rawPath.substring(1);
+ }
+ ArrayList<String> components = new ArrayList<String>(Arrays.asList(rawPath.split("/")));
+ for (int index = 0; index < components.size(); ++index) {
+ if (components.get(index).equals("..")) {
+ components.remove(index);
+ if (index > 0) {
+ components.remove(index-1);
+ --index;
+ }
+ }
+ }
+ StringBuilder normalizedPath = new StringBuilder();
+ for(String component: components) {
+ normalizedPath.append("/");
+ normalizedPath.append(component);
+ }
+ if (isAbsolutePath) {
+ return normalizedPath.toString();
+ } else {
+ return normalizedPath.toString().substring(1);
+ }
+
+
+ }
+
+
@Override
public JSONObject makeEntryForFile(File file) throws JSONException {
String path = this.fullPathForFilesystemPath(file.getAbsolutePath());
@@ -116,7 +156,7 @@ public class LocalFilesystem extends Filesystem {
if (path.startsWith("/")) {
requestedURL = URLforFilesystemPath(path);
} else {
- requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, path));
+ requestedURL = URLforFullPath(normalizePath(inputURL.fullPath + "/" + path));
}
File fp = new File(this.filesystemPathForURL(requestedURL));
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4ce92dff/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 3e054c8..f16470f 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -103,15 +103,48 @@
return path;
}
-- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path
+- (CDVFilesystemURL *)URLforFullPath:(NSString *)fullPath
{
- NSString *fullPath = [self fullPathForFileSystemPath:path];
if (fullPath) {
+ if ([fullPath hasPrefix:@"/"])
return [CDVFilesystemURL fileSystemURLWithString:[NSString stringWithFormat:@"%@://localhost/%@%@", kCDVFilesystemURLPrefix, self.name, fullPath]];
+ return [CDVFilesystemURL fileSystemURLWithString:[NSString stringWithFormat:@"%@://localhost/%@/%@", kCDVFilesystemURLPrefix, self.name, fullPath]];
}
return nil;
}
+- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path
+{
+ return [self URLforFullPath:[self fullPathForFileSystemPath:path]];
+
+}
+
+- (NSString *)normalizePath:(NSString *)rawPath
+{
+ // If this is an absolute path, the first path component will be '/'. Skip it if that's the case
+ BOOL isAbsolutePath = [rawPath hasPrefix:@"/"];
+ if (isAbsolutePath) {
+ rawPath = [rawPath substringFromIndex:1];
+ }
+ NSMutableArray *components = [NSMutableArray arrayWithArray:[rawPath pathComponents]];
+ for (int index = 0; index < [components count]; ++index) {
+ if ([[components objectAtIndex:index] isEqualToString:@".."]) {
+ [components removeObjectAtIndex:index];
+ if (index > 0) {
+ [components removeObjectAtIndex:index-1];
+ --index;
+ }
+ }
+ }
+ NSString *normalizedPath;
+ if (isAbsolutePath) {
+ return [NSString stringWithFormat:@"/%@", [components componentsJoinedByString:@"/"]];
+ } else {
+ return [components componentsJoinedByString:@"/"];
+ }
+
+
+}
- (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options
{
@@ -136,14 +169,19 @@
if ([requestedPath rangeOfString:@":"].location != NSNotFound) {
errorCode = ENCODING_ERR;
} else {
- CDVFilesystemURL* requestedURL = [CDVFilesystemURL fileSystemURLWithURL:[NSURL URLWithString:[requestedPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] relativeToURL:baseURI.url]]; /* TODO: UGLY - FIX */
-
- // NSLog(@"reqFullPath = %@", reqFullPath);
+ // Build new fullPath for the requested resource.
+ // We concatenate the two paths together, and then scan the resulting string to remove
+ // parent ("..") references. Any parent references at the beginning of the string are
+ // silently removed.
+ NSString *combinedPath = [baseURI.fullPath stringByAppendingPathComponent:[requestedPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ combinedPath = [self normalizePath:combinedPath];
+ CDVFilesystemURL* requestedURL = [self URLforFullPath:combinedPath];
+
NSFileManager* fileMgr = [[NSFileManager alloc] init];
BOOL bIsDir;
BOOL bExists = [fileMgr fileExistsAtPath:[self filesystemPathForURL:requestedURL] isDirectory:&bIsDir];
if (bExists && (create == NO) && (bIsDir == !bDirRequest)) {
- // path exists and is of requested type - return TYPE_MISMATCH_ERR
+ // path exists and is not of requested type - return TYPE_MISMATCH_ERR
errorCode = TYPE_MISMATCH_ERR;
} else if (!bExists && (create == NO)) {
// path does not exist and create is false - return NOT_FOUND_ERR
[03/50] git commit: iOS: Add method for testing
backwards-compatiblity of filetransfer plugin
Posted by st...@apache.org.
iOS: Add method for testing backwards-compatiblity of filetransfer plugin
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/4c447801
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/4c447801
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/4c447801
Branch: refs/heads/master
Commit: 4c447801fa18406da48e6b451abf47bfae03016a
Parents: 6f52e3b
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Dec 11 10:46:38 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:16:36 2013 -0500
----------------------------------------------------------------------
src/ios/CDVFile.h | 4 ++++
src/ios/CDVFile.m | 29 ++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4c447801/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 8891174..1f2c812 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -104,6 +104,7 @@ typedef int CDVFileSystemType;
- (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir;
- (NSDictionary *)makeEntryForURL:(NSURL *)URL;
+- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
@@ -134,6 +135,9 @@ typedef int CDVFileSystemType;
- (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
- (NSDictionary *)getDirectoryEntry:(NSString *)target isDirectory:(BOOL)bDirRequest;
+/* Internal methods for testing */
+- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
+
@property (nonatomic, strong) NSString* appDocsPath;
@property (nonatomic, strong) NSString* appLibraryPath;
@property (nonatomic, strong) NSString* appTempPath;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4c447801/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 0634215..517e349 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -201,7 +201,7 @@ NSString* const kCDVFilesystemURLPrefix = @"filesystem";
// Try all installed filesystems, in order. If any one supports mapping from
// path to URL, and returns a URL, then use it.
for (id object in self.fileSystems) {
- localURL = [object fileSystemURLforLocalPath:localPath];
+ localURL = [object URLforFilesystemPath:localPath];
if (localURL)
return localURL;
}
@@ -828,4 +828,31 @@ NSString* const kCDVFilesystemURLPrefix = @"filesystem";
return [self makeEntryForPath:localURL.fullPath fileSystem:localURL.fileSystemType isDirectory:bDirRequest];
}
+#pragma mark Internal methods for testing
+// Internal methods for testing: Get the on-disk location of a local filesystem url.
+// [Currently used for testing file-transfer]
+- (NSString *)_filesystemPathForURL:(CDVFilesystemURL *)localURL
+{
+ CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURL.fileSystemType];
+ if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
+ return [fs filesystemPathForURL:localURL];
+ }
+ return nil;
+}
+
+- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command
+{
+ NSString* localURLstr = [command.arguments objectAtIndex:0];
+ CDVFilesystemURL* localURL = [CDVFilesystemURL fileSystemURLWithString:localURLstr];
+
+ NSString* fsPath = [self _filesystemPathForURL:localURL];
+ CDVPluginResult* result;
+ if (fsPath) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:fsPath];
+ } else {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Cannot resolve URL to a file"];
+ }
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+}
+
@end
[40/50] git commit: CB-5916: Create documents directories if they
don't exist
Posted by st...@apache.org.
CB-5916: Create documents directories if they don't exist
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/620bb7cd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/620bb7cd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/620bb7cd
Branch: refs/heads/master
Commit: 620bb7cd8b47fe67e71e96eaaffa56831b577def
Parents: d5478e5
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 11:46:39 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 11:46:39 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/620bb7cd/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 415d0e2..cc5e8c0 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -118,7 +118,6 @@ public class FileUtils extends CordovaPlugin {
* plugin can continue to provide access to files stored under those
* versions.
*/
- File fp;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
@@ -127,10 +126,11 @@ public class FileUtils extends CordovaPlugin {
persistentRoot = "/data/data/" + packageName;
tempRoot = "/data/data/" + packageName + "/cache/";
}
- // Create the cache dir if it doesn't exist.
- fp = new File(tempRoot);
- fp.mkdirs();
}
+ // Create the directories if they don't exist.
+ new File(tempRoot).mkdirs();
+ new File(persistentRoot).mkdirs();
+
// Register initial filesystems
// Note: The temporary and persistent filesystems need to be the first two
// registered, so that they will match window.TEMPORARY and window.PERSISTENT,
[44/50] git commit: Add default FS root to new FS objects
Posted by st...@apache.org.
Add default FS root to new FS objects
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/aa23cf42
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/aa23cf42
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/aa23cf42
Branch: refs/heads/master
Commit: aa23cf4227880425a3f0e22fe2379b7b38c1b8db
Parents: 7e6afaf
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jan 29 14:02:23 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jan 29 14:02:23 2014 -0500
----------------------------------------------------------------------
www/FileSystem.js | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/aa23cf42/www/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/FileSystem.js b/www/FileSystem.js
index 80a9d2d..6927510 100644
--- a/www/FileSystem.js
+++ b/www/FileSystem.js
@@ -32,6 +32,8 @@ var FileSystem = function(name, root) {
this.name = name || null;
if (root) {
this.root = new DirectoryEntry(root.name, root.fullPath, this);
+ } else {
+ this.root = new DirectoryEntry(this.name, '/', this);
}
};
[12/50] git commit: CB-5699 [BlackBerry10] Update
resolveLocalFileSystemURI implementation
Posted by st...@apache.org.
CB-5699 [BlackBerry10] Update resolveLocalFileSystemURI implementation
The native webkitResolveLocalFileSystemURI does not support accessing URIs
outside of the application sandbox.
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/b7882772
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/b7882772
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/b7882772
Branch: refs/heads/master
Commit: b7882772b329c0690e0eaef264a21661c3e2f659
Parents: a76de41
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Tue Dec 24 10:59:12 2013 -0500
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Tue Dec 24 11:43:58 2013 -0500
----------------------------------------------------------------------
src/blackberry10/index.js | 2 +-
www/blackberry10/fileUtils.js | 2 +-
www/blackberry10/resolveLocalFileSystemURI.js | 58 +++++++++++-----------
3 files changed, 31 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 914d966..9e4cfd3 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -1,7 +1,7 @@
module.exports = {
setSandbox : function (success, fail, args, env) {
require("lib/webview").setSandbox(JSON.parse(decodeURIComponent(args[0])));
- new PluginResult(args, env).noResult(false);
+ new PluginResult(args, env).ok();
},
isSandboxed : function (success, fail, args, env) {
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/www/blackberry10/fileUtils.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/fileUtils.js b/www/blackberry10/fileUtils.js
index 06e676d..740669c 100644
--- a/www/blackberry10/fileUtils.js
+++ b/www/blackberry10/fileUtils.js
@@ -47,6 +47,6 @@ module.exports = {
},
isOutsideSandbox: function (path) {
- return (path.indexOf("accounts/1000/") === 0 || path.indexOf("/accounts/1000/") === 0);
+ return (path.indexOf("accounts/1000") !== -1);
}
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/www/blackberry10/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/resolveLocalFileSystemURI.js b/www/blackberry10/resolveLocalFileSystemURI.js
index 3ede22c..f447a42 100644
--- a/www/blackberry10/resolveLocalFileSystemURI.js
+++ b/www/blackberry10/resolveLocalFileSystemURI.js
@@ -22,36 +22,36 @@
var fileUtils = require('./BB10Utils'),
FileError = require('./FileError');
-function stripURI(uri) {
- var rmFsLocal = uri.substring("filesystem:local:///".length);
- return rmFsLocal.substring(rmFsLocal.indexOf('/') + 1);
-}
-
module.exports = function (uri, success, fail) {
- var sandboxState,
- decodedURI = decodeURI(uri);
- cordova.exec(function (sandboxed) {
- sandboxState = sandboxed;
- }, function (e) {
- console.log("[ERROR]: Could not retrieve sandbox state ", e);
- }, "org.apache.cordova.file", "isSandboxed");
+ var decodedURI = decodeURI(uri).replace(/filesystem:/, '').replace(/local:\/\//, '').replace(/file:\/\//, ''),
+ failNotFound = function () {
+ fail(FileError.NOT_FOUND_ERR);
+ },
+ resolveURI = function () {
+ window.webkitRequestFileSystem(
+ window.PERSISTENT,
+ //todo: match app quota (this is only used for sandboxed fs)
+ 50*1024*1024,
+ function (fs) {
+ fs.root.getFile(
+ decodedURI,
+ { create: false },
+ function (entry) {
+ success(fileUtils.createEntry(entry));
+ },
+ failNotFound
+ );
+ },
+ failNotFound
+ );
+ };
- if (fileUtils.isOutsideSandbox(stripURI(decodedURI))) {
- cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [false]);
- } else {
- cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [true]);
- }
- window.webkitResolveLocalFileSystemURL(decodedURI, function (entry) {
- success(fileUtils.createEntry(entry));
- }, function (e) {
- window.webkitResolveLocalFileSystemURL(decodedURI + '/', function (entry) {
- success(fileUtils.createEntry(entry));
- }, function (e) {
- if (typeof fail === "function") {
- fail(e);
- }
- });
- });
- cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]);
+ cordova.exec(
+ resolveURI,
+ failNotFound,
+ 'org.apache.cordova.file',
+ 'setSandbox',
+ [!fileUtils.isOutsideSandbox(decodedURI)]
+ );
};
[11/50] git commit: CB-5658 Update license comment formatting of
doc/index.md
Posted by st...@apache.org.
CB-5658 Update license comment formatting of doc/index.md
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/a76de41b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a76de41b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a76de41b
Branch: refs/heads/master
Commit: a76de41b6a348fd754aefb26f4f1c3485893b9b6
Parents: 9ae1302
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Dec 18 21:11:02 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Dec 18 21:11:02 2013 -0500
----------------------------------------------------------------------
doc/index.md | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a76de41b/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 9044d29..0c26700 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -1,20 +1,20 @@
<!---
- license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
-->
# org.apache.cordova.file
[09/50] git commit: CB-5658 Delete stale snapshot of plugin docs
Posted by st...@apache.org.
CB-5658 Delete stale snapshot of plugin docs
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/c8480221
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/c8480221
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/c8480221
Branch: refs/heads/master
Commit: c8480221b3b3985900621ea39132a0b379a18ae9
Parents: eb28b7a
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Dec 17 20:49:39 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Dec 17 20:49:39 2013 -0500
----------------------------------------------------------------------
docs/directoryentry/directoryentry.md | 390 -----------------------
docs/directoryreader/directoryreader.md | 69 ----
docs/file.md | 91 ------
docs/fileentry/fileentry.md | 323 -------------------
docs/fileerror/fileerror.md | 51 ---
docs/fileobj/fileobj.md | 83 -----
docs/filereader/filereader.md | 259 ---------------
docs/filesystem/filesystem.md | 95 ------
docs/fileuploadoptions/fileuploadoptions.md | 47 ---
docs/fileuploadresult/fileuploadresult.md | 42 ---
docs/filewriter/filewriter.md | 233 --------------
docs/flags/flags.md | 49 ---
docs/localfilesystem/localfilesystem.md | 110 -------
docs/metadata/metadata.md | 54 ----
14 files changed, 1896 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/directoryentry/directoryentry.md
----------------------------------------------------------------------
diff --git a/docs/directoryentry/directoryentry.md b/docs/directoryentry/directoryentry.md
deleted file mode 100644
index e21aa5f..0000000
--- a/docs/directoryentry/directoryentry.md
+++ /dev/null
@@ -1,390 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-DirectoryEntry
-==============
-
-This object represents a directory on a file system, as defined by the
-[W3C Directories and Systems](http://www.w3.org/TR/file-system-api/)
-specification.
-
-Properties
-----------
-
-- __isFile__: Always false. _(boolean)_
-- __isDirectory__: Always true. _(boolean)_
-- __name__: The name of the `DirectoryEntry`, excluding the path leading to it. _(DOMString)_
-- __fullPath__: The full absolute path from the root to the `DirectoryEntry`. _(DOMString)_
-
-__NOTE:__ The following attribute is defined by the W3C specification,
-but is _not_ supported:
-
-- __filesystem__: The file system on which the `DirectoryEntry` resides. _(FileSystem)_
-
-Methods
--------
-
-The following methods can be invoked on a `DirectoryEntry` object:
-
-- __getMetadata__: Look up metadata about a directory.
-- __setMetadata__: Set metadata on a directory.
-- __moveTo__: Move a directory to a different location on the file system.
-- __copyTo__: Copy a directory to a different location on the file system.
-- __toURL__: Return a URL to help locate a directory.
-- __remove__: Delete a directory. The directory must be empty.
-- __getParent__: Look up the parent directory.
-- __createReader__: Create a new `DirectoryReader` that can read entries from a directory.
-- __getDirectory__: Create or look up a directory.
-- __getFile__: Create or look up a file.
-- __removeRecursively__: Delete a directory and all of its contents.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-getMetadata
------------
-
-Look up metadata about a directory.
-
-__Parameters:__
-
-- __successCallback__: A callback function to execute with a `Metadata` object. _(Function)_
-- __errorCallback__: A callback function to execute if an error occurs when retrieving the `Metadata`. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(metadata) {
- console.log("Last Modified: " + metadata.modificationTime);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- // Request the metadata object for this entry
- entry.getMetadata(success, fail);
-
-setMetadata
-----------------
-
-Set metadata on a directory.
-__Currently works only on iOS.__ - this will set the extended attributes of a directory.
-
-__Parameters:__
-
-- __successCallback__: A callback that executes when the metadata is successfully set. _(Function)_
-- __errorCallback__: A callback that executes when the metadata fails to be set. _(Function)_
-- __metadataObject__: An object that contains the metadata's keys and values. _(Object)_
-
-__Quick Example__
-
- function success() {
- console.log("The metadata was successfully set.");
- }
-
- function fail() {
- alert("There was an error in setting the metadata");
- }
-
- // Set the metadata
- entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1});
-
-__iOS Quirk__
-
-- Only the `com.apple.MobileBackup` extended attribute is supported. Set the value to `1` to prevent the directory from being backed up to iCloud. Set the value to `0` to re-enable the directory to be backed up to iCloud.
-
-__Quick Example__
-
- function setFolderMetadata(localFileSystem, subFolder, metadataKey, metadataValue)
- {
- var onSetMetadataWin = function() {
- console.log("success setting metadata")
- }
- var onSetMetadataFail = function() {
- console.log("error setting metadata")
- }
-
- var onGetDirectoryWin = function(parent) {
- var data = {};
- data[metadataKey] = metadataValue;
- parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data);
- }
- var onGetDirectoryFail = function() {
- console.log("error getting dir")
- }
-
- var onFSWin = function(fileSystem) {
- fileSystem.root.getDirectory(subFolder, {create: true, exclusive: false}, onGetDirectoryWin, onGetDirectoryFail);
- }
-
- var onFSFail = function(evt) {
- console.log(evt.target.error.code);
- }
-
- window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail);
- }
-
- setFolderMetadata(LocalFileSystem.PERSISTENT, "Backups", "com.apple.MobileBackup", 1);
-
-moveTo
-------
-
-Move a directory to a different location on the file system. An error results if the app attempts to:
-
-- move a directory inside itself or to any child at any depth.
-- move a directory into its parent if a name different from its current directory is not provided.
-- move a directory to a path occupied by a file.
-- move a directory to a path occupied by a directory that is not empty.
-
-Moving a directory on top of an existing empty directory attempts to
-delete and replace that directory.
-
-__Parameters:__
-
-- __parent__: The parent directory to which to move the directory. _(DirectoryEntry)_
-- __newName__: The new name of the directory. Defaults to the current name if unspecified. _(DOMString)_
-- __successCallback__: A callback that executes with the `DirectoryEntry` object for the new directory. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to move the directory. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(entry) {
- console.log("New Path: " + entry.fullPath);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- function moveDir(entry) {
- var parent = document.getElementById('parent').value,
- parentName = parent.substring(parent.lastIndexOf('/')+1),
- newName = document.getElementById('newName').value,
- parentEntry = new DirectoryEntry(parentName, parent);
-
- // move the directory to a new directory and rename it
- entry.moveTo(parentEntry, newName, success, fail);
- }
-
-copyTo
-------
-
-Copy a directory to a different location on the file system. An error results if the app attempts to:
-
-- copy a directory inside itself at any depth.
-- copy a directory into its parent if a name different from its current directory is not provided.
-
-Directory copies are always recursive, and copy all contents of the directory.
-
-__Parameters:__
-
-- __parent__: The parent directory to which to copy the directory. _(DirectoryEntry)_
-- __newName__: The new name of the directory. Defaults to the current name if unspecified. _(DOMString)_
-- __successCallback__: A callback that executes with the `DirectoryEntry` object for the new directory. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to copy the underlying directory. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function win(entry) {
- console.log("New Path: " + entry.fullPath);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- function copyDir(entry) {
- var parent = document.getElementById('parent').value,
- parentName = parent.substring(parent.lastIndexOf('/')+1),
- newName = document.getElementById('newName').value,
- parentEntry = new DirectoryEntry(parentName, parent);
-
- // copy the directory to a new directory and rename it
- entry.copyTo(parentEntry, newName, success, fail);
- }
-
-toURL
------
-
-Returns a URL that can be used to locate the directory.
-
-__Quick Example__
-
- // Get the URL for this directory
- var dirURL = entry.toURL();
- console.log(dirURL);
-
-remove
-------
-
-Deletes a directory. An error results if the app attempts to:
-
-- delete a directory that is not empty.
-- delete the root directory of a filesystem.
-
-__Parameters:__
-
-- __successCallback__: A callback that executes after the directory is deleted. Invoked with no parameters. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to delete the directory. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(entry) {
- console.log("Removal succeeded");
- }
-
- function fail(error) {
- alert('Error removing directory: ' + error.code);
- }
-
- // remove this directory
- entry.remove(success, fail);
-
-getParent
----------
-
-Look up the parent `DirectoryEntry` containing the directory.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed the directory's parent `DirectoryEntry`. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to retrieve the parent `DirectoryEntry`. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(parent) {
- console.log("Parent Name: " + parent.name);
- }
-
- function fail(error) {
- alert('Failed to get parent directory: ' + error.code);
- }
-
- // Get the parent DirectoryEntry
- entry.getParent(success, fail);
-
-createReader
-------------
-
-Creates a new DirectoryReader to read entries in a directory.
-
-__Quick Example__
-
- // create a directory reader
- var directoryReader = entry.createReader();
-
-getDirectory
-------------
-
-Creates or looks up an existing directory. An error results if the app attempts to:
-
-- create a directory whose immediate parent does not yet exist.
-
-__Parameters:__
-
-- __path__: The path to the directory to be looked up or created. Either an absolute path, or a relative path from this `DirectoryEntry`. _(DOMString)_
-- __options__: Options to specify whether the directory is to be created if it doesn't exist. _(Flags)_
-- __successCallback__: A callback that executes with a `DirectoryEntry` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when creating or looking up the directory. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(parent) {
- console.log("Parent Name: " + parent.name);
- }
-
- function fail(error) {
- alert("Unable to create new directory: " + error.code);
- }
-
- // Retrieve an existing directory, or create it if it does not already exist
- entry.getDirectory("newDir", {create: true, exclusive: false}, success, fail);
-
-getFile
--------
-
-Creates or looks up a file. An error results if the app attempts to:
-
-- create a file whose immediate parent does not yet exist.
-
-__Parameters:__
-
-- __path__: The path to the file to be looked up or created. Either an absolute path, or a relative path from this `DirectoryEntry`. _(DOMString)_
-- __options__: Options to specify whether the file is created if it doesn't exist. _(Flags)_
-- __successCallback__: A callback that is passed a `FileEntry` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when creating or looking up the file. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(parent) {
- console.log("Parent Name: " + parent.name);
- }
-
- function fail(error) {
- alert("Failed to retrieve file: " + error.code);
- }
-
- // Retrieve an existing file, or create it if it does not exist
- entry.getFile("newFile.txt", {create: true, exclusive: false}, success, fail);
-
-removeRecursively
------------------
-
-Deletes a directory and all of its contents. In the event of an error (such as trying to delete
-a directory containing a file that cannot be removed), some of the contents of the directory may
-be deleted. An error results if the app attempts to:
-
-- delete the root directory of a filesystem.
-
-__Parameters:__
-
-- __successCallback__: A callback that executes after the `DirectoryEntry` has been deleted. Invoked with no parameters. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to delete the `DirectoryEntry`. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(parent) {
- console.log("Remove Recursively Succeeded");
- }
-
- function fail(error) {
- alert("Failed to remove directory or it's contents: " + error.code);
- }
-
- // remove the directory and all it's contents
- entry.removeRecursively(success, fail);
-
-BlackBerry Quirks
------------------
-
-May fail with a `ControlledAccessException` in the following cases:
-
-- An app attempts to access a directory created by a previous installation of the app.
-
-> Solution: ensure temporary directories are cleaned manually, or by the application prior to reinstallation.
-
-- If the device is connected by USB.
-
-> Solution: disconnect the USB cable from the device and run again.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/directoryreader/directoryreader.md
----------------------------------------------------------------------
diff --git a/docs/directoryreader/directoryreader.md b/docs/directoryreader/directoryreader.md
deleted file mode 100644
index b37edb9..0000000
--- a/docs/directoryreader/directoryreader.md
+++ /dev/null
@@ -1,69 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-DirectoryReader
-===============
-
-An object that lists files and directories within a directory, as
-defined in the
-[W3C Directories and Systems](http://www.w3.org/TR/file-system-api/)
-specification.
-
-Methods
--------
-
-- __readEntries__: Read the entries in a directory.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-readEntries
------------
-
-Read the entries in this directory.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed an array of `FileEntry` and `DirectoryEntry` objects. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when retrieving the directory listing. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(entries) {
- var i;
- for (i=0; i<entries.length; i++) {
- console.log(entries[i].name);
- }
- }
-
- function fail(error) {
- alert("Failed to list directory contents: " + error.code);
- }
-
- // Get a directory reader
- var directoryReader = dirEntry.createReader();
-
- // Get a list of all the entries in the directory
- directoryReader.readEntries(success,fail);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/file.md
----------------------------------------------------------------------
diff --git a/docs/file.md b/docs/file.md
deleted file mode 100644
index eed64c0..0000000
--- a/docs/file.md
+++ /dev/null
@@ -1,91 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-File
-==========
-
-> An API to read, write and navigate file system hierarchies, based on the [W3C File API](http://www.w3.org/TR/FileAPI).
-
-Objects
--------
-
-- DirectoryEntry
-- DirectoryReader
-- File
-- FileEntry
-- FileError
-- FileReader
-- FileSystem
-- FileTransfer
-- FileTransferError
-- FileUploadOptions
-- FileUploadResult
-- FileWriter
-- Flags
-- LocalFileSystem
-- Metadata
-
-Permissions
------------
-
-### Android
-
-#### app/res/xml/config.xml
-
- <plugin name="File" value="org.apache.cordova.FileUtils" />
- <plugin name="FileTransfer" value="org.apache.cordova.FileTransfer" />
-
-#### app/AndroidManifest.xml
-
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
-### Bada
-
- No permissions are required.
-
-### BlackBerry WebWorks
-
-#### www/plugins.xml
-
- <plugin name="File" value="org.apache.cordova.file.FileManager" />
- <plugin name="FileTransfer" value="org.apache.cordova.http.FileTransfer" />
-
-#### www/config.xml
-
- <feature id="blackberry.io.file" required="true" version="1.0.0.0" />
- <feature id="blackberry.utils" required="true" version="1.0.0.0" />
- <feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
- <rim:permissions>
- <rim:permit>access_shared</rim:permit>
- </rim:permissions>
-
-### iOS
-
-#### config.xml
-
- <plugin name="File" value="CDVFile" />
- <plugin name="FileTransfer" value="CDVFileTransfer" />
-
-### webOS
-
- No permissions are required.
-
-### Windows Phone
-
- No permissions are required.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/fileentry/fileentry.md
----------------------------------------------------------------------
diff --git a/docs/fileentry/fileentry.md b/docs/fileentry/fileentry.md
deleted file mode 100644
index f362833..0000000
--- a/docs/fileentry/fileentry.md
+++ /dev/null
@@ -1,323 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileEntry
-==========
-
-Represents a file on a file system, as defined in the
-[W3C Directories and Systems](http://www.w3.org/TR/file-system-api/)
-specification.
-
-Properties
-----------
-
-- __isFile__: Always true. _(boolean)_
-- __isDirectory__: Always false. _(boolean)_
-- __name__: The name of the `FileEntry`, excluding the path leading to it. _(DOMString)_
-- __fullPath__: The full absolute path from the root to the `FileEntry`. _(DOMString)_
-
-__NOTE:__ The following attribute is defined by the W3C specification,
-but is _not_ supported:
-
-- __filesystem__: The file system on which the `FileEntry` resides. _(FileSystem)_
-
-Methods
--------
-
-- __getMetadata__: Look up metadata about a file.
-- __setMetadata__: Set metadata on a file.
-- __moveTo__: Move a file to a different location on the file system.
-- __copyTo__: Copy a file to a different location on the file system.
-- __toURL__: Return a URL that can be used to locate a file.
-- __remove__: Delete a file.
-- __getParent__: Look up the parent directory.
-- __createWriter__: Creates a `FileWriter` object that can be used to write to a file.
-- __file__: Creates a `File` object containing file properties.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-getMetadata
-----------------
-
-Look up metadata about a file.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed a `Metadata` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when retrieving the `Metadata`. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(metadata) {
- console.log("Last Modified: " + metadata.modificationTime);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- // Request the metadata object for this entry
- entry.getMetadata(success, fail);
-
-setMetadata
-----------------
-
-Set metadata on a file.
-
-__Currently works only on iOS.__
-- this will set the extended attributes of a file.
-
-__Parameters:__
-
-- __successCallback__: A callback that executes when the metadata is set. _(Function)_
-- __errorCallback__: A callback that executes when the metadata is not successfully set. _(Function)_
-- __metadataObject__: An object that contains the metadata's keys and values. _(Object)_
-
-__Quick Example__
-
- function success() {
- console.log("The metadata was successfully set.");
- }
-
- function fail() {
- alert("There was an error in setting the metadata");
- }
-
- // Set the metadata
- entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1});
-
-__iOS Quirk__
-
-- Only the `com.apple.MobileBackup` extended attribute is supported. Set the value to `1` to prevent the file from being backed up to iCloud. Set the value to `0` to re-enable the file to be backed up to iCloud.
-
-__Quick Example__
-
- function setFileMetadata(localFileSystem, filePath, metadataKey, metadataValue)
- {
- var onSetMetadataWin = function() {
- console.log("success setting metadata")
- }
- var onSetMetadataFail = function() {
- console.log("error setting metadata")
- }
-
- var onGetFileWin = function(parent) {
- var data = {};
- data[metadataKey] = metadataValue;
- parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data);
- }
- var onGetFileFail = function() {
- console.log("error getting file")
- }
-
- var onFSWin = function(fileSystem) {
- fileSystem.root.getFile(filePath, {create: true, exclusive: false}, onGetFileWin, onGetFileFail);
- }
-
- var onFSFail = function(evt) {
- console.log(evt.target.error.code);
- }
-
- window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail);
- }
-
- setFileMetadata(LocalFileSystem.PERSISTENT, "Backups/sqlite.db", "com.apple.MobileBackup", 1);
-
-moveTo
-------
-
-Move a file to a different location on the file system. An error
-results if the app attempts to:
-
-- move a file into its parent if a name different from its current one isn't provided;
-- move a file to a path occupied by a directory;
-
-In addition, moving a file on top of an existing file attempts to
-delete and replace that file.
-
-__Parameters:__
-
-- __parent__: The parent directory to which to move the file. _(DirectoryEntry)_
-- __newName__: The new name of the file. Defaults to the current name if unspecified. _(DOMString)_
-- __successCallback__: A callback that is passed the new files `FileEntry` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to move the file. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(entry) {
- console.log("New Path: " + entry.fullPath);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- function moveFile(entry) {
- var parent = document.getElementById('parent').value,
- parentName = parent.substring(parent.lastIndexOf('/')+1),
- parentEntry = new DirectoryEntry(parentName, parent);
-
- // move the file to a new directory and rename it
- entry.moveTo(parentEntry, "newFile.txt", success, fail);
- }
-
-copyTo
-------
-
-Copy a file to a new location on the file system. An error results if
-the app attempts to:
-
-- copy a file into its parent if a name different from its current one is not provided.
-
-__Parameters:__
-
-- __parent__: The parent directory to which to copy the file. _(DirectoryEntry)_
-- __newName__: The new name of the file. Defaults to the current name if unspecified. _(DOMString)_
-- __successCallback__: A callback that is passed the new file's `FileEntry` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to copy the file. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function win(entry) {
- console.log("New Path: " + entry.fullPath);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- function copyFile(entry) {
- var parent = document.getElementById('parent').value,
- parentName = parent.substring(parent.lastIndexOf('/')+1),
- parentEntry = new DirectoryEntry(parentName, parent);
-
- // copy the file to a new directory and rename it
- entry.copyTo(parentEntry, "file.copy", success, fail);
- }
-
-toURL
------
-
-Returns a URL that can be used to locate the file.
-
-__Quick Example__
-
- // Request the URL for this entry
- var fileURL = entry.toURL();
- console.log(fileURL);
-
-remove
-------
-
-Deletes a file.
-
-__Parameters:__
-
-- __successCallback__: A callback that executes after the file has been deleted. Invoked with no parameters. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to delete the file. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(entry) {
- console.log("Removal succeeded");
- }
-
- function fail(error) {
- alert('Error removing file: ' + error.code);
- }
-
- // remove the file
- entry.remove(success, fail);
-
-getParent
----------
-
-Look up the parent `DirectoryEntry` containing the file.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed the file's parent `DirectoryEntry`. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when attempting to retrieve the parent `DirectoryEntry`. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(parent) {
- console.log("Parent Name: " + parent.name);
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- // Get the parent DirectoryEntry
- entry.getParent(success, fail);
-
-createWriter
-------------
-
-Create a `FileWriter` object associated with the file represented by the `FileEntry`.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed a `FileWriter` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs while attempting to create the FileWriter. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(writer) {
- writer.write("Some text to the file");
- }
-
- function fail(error) {
- alert(error.code);
- }
-
- // create a FileWriter to write to the file
- entry.createWriter(success, fail);
-
-file
-----
-
-Return a `File` object that represents the current state of the file
-that this `FileEntry` represents.
-
-__Parameters:__
-
-- __successCallback__: A callback that is passed a `File` object. _(Function)_
-- __errorCallback__: A callback that executes if an error occurs when creating the `File` object, such as when the file no longer exists. Invoked with a `FileError` object. _(Function)_
-
-__Quick Example__
-
- function success(file) {
- console.log("File size: " + file.size);
- }
-
- function fail(error) {
- alert("Unable to retrieve file properties: " + error.code);
- }
-
- // obtain properties of a file
- entry.file(success, fail);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/fileerror/fileerror.md
----------------------------------------------------------------------
diff --git a/docs/fileerror/fileerror.md b/docs/fileerror/fileerror.md
deleted file mode 100644
index 1d7f39f..0000000
--- a/docs/fileerror/fileerror.md
+++ /dev/null
@@ -1,51 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileError
-========
-
-A `FileError` object is set when an error occurs in any of the File API methods.
-
-Properties
-----------
-
-- __code__: One of the predefined error codes listed below.
-
-Constants
----------
-
-- `FileError.NOT_FOUND_ERR`
-- `FileError.SECURITY_ERR`
-- `FileError.ABORT_ERR`
-- `FileError.NOT_READABLE_ERR`
-- `FileError.ENCODING_ERR`
-- `FileError.NO_MODIFICATION_ALLOWED_ERR`
-- `FileError.INVALID_STATE_ERR`
-- `FileError.SYNTAX_ERR`
-- `FileError.INVALID_MODIFICATION_ERR`
-- `FileError.QUOTA_EXCEEDED_ERR`
-- `FileError.TYPE_MISMATCH_ERR`
-- `FileError.PATH_EXISTS_ERR`
-
-Description
------------
-
-The `FileError` object is the only parameter provided to any of the
-File API's error callbacks. To determine the type of error, compare
-its `code` property to any of the listings above.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/fileobj/fileobj.md
----------------------------------------------------------------------
diff --git a/docs/fileobj/fileobj.md b/docs/fileobj/fileobj.md
deleted file mode 100644
index ee5f1d4..0000000
--- a/docs/fileobj/fileobj.md
+++ /dev/null
@@ -1,83 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-File
-====
-
-This object contains attributes of a single file.
-
-Properties
-----------
-
-- __name__: The name of the file. _(DOMString)_
-- __fullPath__: The full path of the file including the file name. _(DOMString)_
-- __type__: The mime type of the file. _(DOMString)_
-- __lastModifiedDate__: The last time the file was modified. _(Date)_
-- __size__: The size of the file in bytes. _(long)_
-
-Methods
--------
-
-- __slice__: Select only a portion of the file to be read.
-
-Details
--------
-
-The `File` object contains attributes of a single file. You can get
-an instance of a `File` object by calling a `FileEntry` object's
-`file()` method.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-slice
---------------
-
-Return a new `File` object, for which `FileReader` returns only the
-specified portion of the file. Negative values for `start` or `end`
-are measured from the end of the file. Indexes are positioned
-relative to the current slice. (See the full example below.)
-
-__Parameters:__
-
-- __start__: The index of the first byte to read, inclusive.
-- __end__: The index of the byte after the last one to read.
-
-__Quick Example__
-
- var slicedFile = file.slice(10, 30);
-
-__Full Example__
-
- var slice1 = file.slice(100, 400);
- var slice2 = slice1.slice(20, 35);
-
- var slice3 = file.slice(120, 135);
- // slice2 and slice3 are equivalent.
-
-__Supported Platforms:__
-
-- Android
-- iOS
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/filereader/filereader.md
----------------------------------------------------------------------
diff --git a/docs/filereader/filereader.md b/docs/filereader/filereader.md
deleted file mode 100644
index 25f6ff0..0000000
--- a/docs/filereader/filereader.md
+++ /dev/null
@@ -1,259 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileReader
-==========
-
-The `FileReader` allows basic access to a file.
-
-Properties
-----------
-
-- __readyState__: One of the reader's three possible states, either `EMPTY`, `LOADING` or `DONE`.
-- __result__: The contents of the file that have been read. _(DOMString)_
-- __error__: An object containing errors. _(FileError)_
-- __onloadstart__: Called when the read starts. _(Function)_
-- __onload__: Called when the read has successfully completed. _(Function)_
-- __onabort__: Called when the read has been aborted. For instance, by invoking the `abort()` method. _(Function)_
-- __onerror__: Called when the read has failed. _(Function)_
-- __onloadend__: Called when the request has completed (either in success or failure). _(Function)_
-
-__NOTE:__ The following porperty is not supported:
-
-- __onprogress__: Called while reading the file, reporting progress in terms of `progress.loaded`/`progress.total`. _(Function)_
-
-Methods
--------
-
-- __abort__: Aborts reading file.
-- __readAsDataURL__: Read file and return data as a base64-encoded data URL.
-- __readAsText__: Reads text file.
-- __readAsBinaryString__: Reads file as binary and returns a binary string.
-- __readAsArrayBuffer__: Reads file as an `ArrayBuffer`.
-
-Details
--------
-
-The `FileReader` object offers a way to read files from the device's
-file system. Files can be read as text or as a base64 data-encoded
-string. Event listeners receive the `loadstart`, `progress`, `load`,
-`loadend`, `error`, and `abort` events.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-Read As Data URL
-----------------
-
-__Parameters:__
-
-- __file__: the file object to read.
-
-Quick Example
--------------
-
- function win(file) {
- var reader = new FileReader();
- reader.onloadend = function (evt) {
- console.log("read success");
- console.log(evt.target.result);
- };
- reader.readAsDataURL(file);
- };
-
- var fail = function (evt) {
- console.log(error.code);
- };
-
- entry.file(win, fail);
-
-Read As Text
-------------
-
-__Parameters:__
-
-- __file__: the file object to read.
-- __encoding__: the encoding to use to encode the file's content. Default is UTF8.
-
-Quick Example
--------------
-
- function win(file) {
- var reader = new FileReader();
- reader.onloadend = function (evt) {
- console.log("read success");
- console.log(evt.target.result);
- };
- reader.readAsText(file);
- };
-
- var fail = function (evt) {
- console.log(error.code);
- };
-
- entry.file(win, fail);
-
-Abort Quick Example
--------------------
-
- function win(file) {
- var reader = new FileReader();
- reader.onloadend = function(evt) {
- console.log("read success");
- console.log(evt.target.result);
- };
- reader.readAsText(file);
- reader.abort();
- };
-
- function fail(error) {
- console.log(error.code);
- }
-
- entry.file(win, fail);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>FileReader Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for device API libraries to load
- //
- function onLoad() {
- document.addEventListener("deviceready", onDeviceReady, false);
- }
-
- // device APIs are available
- //
- function onDeviceReady() {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
- }
-
- function gotFS(fileSystem) {
- fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
- }
-
- function gotFileEntry(fileEntry) {
- fileEntry.file(gotFile, fail);
- }
-
- function gotFile(file){
- readDataUrl(file);
- readAsText(file);
- }
-
- function readDataUrl(file) {
- var reader = new FileReader();
- reader.onloadend = function(evt) {
- console.log("Read as data URL");
- console.log(evt.target.result);
- };
- reader.readAsDataURL(file);
- }
-
- function readAsText(file) {
- var reader = new FileReader();
- reader.onloadend = function(evt) {
- console.log("Read as text");
- console.log(evt.target.result);
- };
- reader.readAsText(file);
- }
-
- function fail(evt) {
- console.log(evt.target.error.code);
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>Read File</p>
- </body>
- </html>
-
-iOS Quirks
-----------
-- The __encoding__ parameter is not supported, and UTF8 encoding is always in effect.
-
-Read As Binary String
----------------------
-
-Currently supported on iOS and Android only.
-
-__Parameters:__
-
-- __file__: the file object to read.
-
-Quick Example
--------------
-
- function win(file) {
- var reader = new FileReader();
- reader.onloadend = function (evt) {
- console.log("read success");
- console.log(evt.target.result);
- };
- reader.readAsBinaryString(file);
- };
-
- var fail = function (evt) {
- console.log(error.code);
- };
-
- entry.file(win, fail);
-
-Read As Array Buffer
---------------------
-
-Currently supported on iOS and Android only.
-
-__Parameters:__
-
-- __file__: the file object to read.
-
-Quick Example
--------------
-
- function win(file) {
- var reader = new FileReader();
- reader.onloadend = function (evt) {
- console.log("read success");
- console.log(new Uint8Array(evt.target.result));
- };
- reader.readAsArrayBuffer(file);
- };
-
- var fail = function (evt) {
- console.log(error.code);
- };
-
- entry.file(win, fail);
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/filesystem/filesystem.md
----------------------------------------------------------------------
diff --git a/docs/filesystem/filesystem.md b/docs/filesystem/filesystem.md
deleted file mode 100644
index c8eaa2c..0000000
--- a/docs/filesystem/filesystem.md
+++ /dev/null
@@ -1,95 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileSystem
-==========
-
-This object represents a file system.
-
-Properties
-----------
-
-- __name__: The name of the file system. _(DOMString)_
-- __root__: The root directory of the file system. _(DirectoryEntry)_
-
-Details
--------
-
-The `FileSystem` object represents information about the file system.
-The name of the file system is unique across the list of exposed
-file systems. The root property contains a `DirectoryEntry` object
-that represents the file system's root directory.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-File System Quick Example
--------------------------
-
- function onSuccess(fileSystem) {
- console.log(fileSystem.name);
- console.log(fileSystem.root.name);
- }
-
- // request the persistent file system
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>File System Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for device API libraries to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // device APIs are available
- //
- function onDeviceReady() {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
- }
-
- function onFileSystemSuccess(fileSystem) {
- console.log(fileSystem.name);
- console.log(fileSystem.root.name);
- }
-
- function fail(evt) {
- console.log(evt.target.error.code);
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>File System</p>
- </body>
- </html>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/fileuploadoptions/fileuploadoptions.md
----------------------------------------------------------------------
diff --git a/docs/fileuploadoptions/fileuploadoptions.md b/docs/fileuploadoptions/fileuploadoptions.md
deleted file mode 100644
index e0e6fe2..0000000
--- a/docs/fileuploadoptions/fileuploadoptions.md
+++ /dev/null
@@ -1,47 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileUploadOptions
-========
-
-A `FileUploadOptions` object can be passed to the `FileTransfer`
-object's `upload()` method to specify additional parameters to the
-upload script.
-
-Properties
-----------
-
-- __fileKey__: The name of the form element. Defaults to `file`. (DOMString)
-- __fileName__: The file name to use when saving the file on the server. Defaults to `image.jpg`. (DOMString)
-- __mimeType__: The mime type of the data to upload. Defaults to `image/jpeg`. (DOMString)
-- __params__: A set of optional key/value pairs to pass in the HTTP request. (Object)
-- __chunkedMode__: Whether to upload the data in chunked streaming mode. Defaults to `true`. (Boolean)
-- __headers__: A map of header name/header values. Use an array to specify more than one value. (Object)
-
-Description
------------
-
-A `FileUploadOptions` object can be passed to the `FileTransfer`
-object's `upload()` method to specify additional parameters to the
-upload script.
-
-WP7 Quirk
----------
-
-- __chunkedMode:__: Ignored on WP7.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/fileuploadresult/fileuploadresult.md
----------------------------------------------------------------------
diff --git a/docs/fileuploadresult/fileuploadresult.md b/docs/fileuploadresult/fileuploadresult.md
deleted file mode 100644
index 4d9305a..0000000
--- a/docs/fileuploadresult/fileuploadresult.md
+++ /dev/null
@@ -1,42 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileUploadResult
-========
-
-A `FileUploadResult` object is passed to the success callback of the
-`FileTransfer` object's `upload()` method.
-
-Properties
-----------
-
-- __bytesSent__: The number of bytes sent to the server as part of the upload. (long)
-- __responseCode__: The HTTP response code returned by the server. (long)
-- __response__: The HTTP response returned by the server. (DOMString)
-
-Description
------------
-
-The `FileUploadResult` object is returned via the success callback of
-the `FileTransfer` object's `upload()` method.
-
-iOS Quirks
-----------
-
-- Does not support `responseCode` or `bytesSent`.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/filewriter/filewriter.md
----------------------------------------------------------------------
diff --git a/docs/filewriter/filewriter.md b/docs/filewriter/filewriter.md
deleted file mode 100644
index 2269c06..0000000
--- a/docs/filewriter/filewriter.md
+++ /dev/null
@@ -1,233 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-FileWriter
-==========
-
-As object that allows you to create and write data to a file.
-
-Properties
-----------
-
-- __readyState__: One of the three possible states, either `INIT`, `WRITING`, or `DONE`.
-- __fileName__: The name of the file to be written. _(DOMString)_
-- __length__: The length of the file to be written. _(long)_
-- __position__: The current position of the file pointer. _(long)_
-- __error__: An object containing errors. _(FileError)_
-- __onwritestart__: Called when the write starts. _(Function)_
-- __onwrite__: Called when the request has completed successfully. _(Function)_
-- __onabort__: Called when the write has been aborted. For instance, by invoking the abort() method. _(Function)_
-- __onerror__: Called when the write has failed. _(Function)_
-- __onwriteend__: Called when the request has completed (either in success or failure). _(Function)_
-
-The following property is _not_ supported:
-
-- __onprogress__: Called while writing the file, reporting progress in terms of `progress.loaded`/`progress.total`. _(Function)_
-Methods
--------
-
-- __abort__: Aborts writing the file.
-- __seek__: Moves the file pointer to the specified byte.
-- __truncate__: Shortens the file to the specified length.
-- __write__: Writes data to the file.
-
-Details
--------
-
-The `FileWriter` object offers a way to write UTF-8 encoded files to
-the device file system. Applications respond to `writestart`,
-`progress`, `write`, `writeend`, `error`, and `abort` events.
-
-Each `FileWriter` corresponds to a single file, to which data can be
-written many times. The `FileWriter` maintains the file's `position`
-and `length` attributes, which allow the app to `seek` and `write`
-anywhere in the file. By default, the `FileWriter` writes to the
-beginning of the file, overwriting existing data. Set the optional
-`append` boolean to `true` in the `FileWriter`'s constructor to
-write to the end of the file.
-
-Text data is supported by all platforms listed below. Text is encoded as UTF-8 before being written to the filesystem. Some platforms also support binary data, which can be passed in as either an ArrayBuffer or a Blob.
-
-Supported Platforms
--------------------
-
-### Text and Binary suport
-
-- Android
-- iOS
-
-### Text only support
-
-- BlackBerry WebWorks (OS 5.0 and higher)
-- Windows Phone 7 and 8
-- Windows 8
-
-Seek Quick Example
-------------------------------
-
- function win(writer) {
- // fast forwards file pointer to end of file
- writer.seek(writer.length);
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Truncate Quick Example
---------------------------
-
- function win(writer) {
- writer.truncate(10);
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Write Quick Example
--------------------
-
- function win(writer) {
- writer.onwrite = function(evt) {
- console.log("write success");
- };
- writer.write("some sample text");
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Binary Write Quick Example
---------------------------
-
- function win(writer) {
- var data = new ArrayBuffer(5),
- dataView = new Int8Array(data);
- for (i=0; i < 5; i++) {
- dataView[i] = i;
- }
- writer.onwrite = function(evt) {
- console.log("write success");
- };
- writer.write(data);
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Append Quick Example
---------------------
-
- function win(writer) {
- writer.onwrite = function(evt) {
- console.log("write success");
- };
- writer.seek(writer.length);
- writer.write("appended text");
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Abort Quick Example
--------------------
-
- function win(writer) {
- writer.onwrite = function(evt) {
- console.log("write success");
- };
- writer.write("some sample text");
- writer.abort();
- };
-
- var fail = function(evt) {
- console.log(error.code);
- };
-
- entry.createWriter(win, fail);
-
-Full Example
-------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>FileWriter Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for device API libraries to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // device APIs are available
- //
- function onDeviceReady() {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
- }
-
- function gotFS(fileSystem) {
- fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
- }
-
- function gotFileEntry(fileEntry) {
- fileEntry.createWriter(gotFileWriter, fail);
- }
-
- function gotFileWriter(writer) {
- writer.onwriteend = function(evt) {
- console.log("contents of file now 'some sample text'");
- writer.truncate(11);
- writer.onwriteend = function(evt) {
- console.log("contents of file now 'some sample'");
- writer.seek(4);
- writer.write(" different text");
- writer.onwriteend = function(evt){
- console.log("contents of file now 'some different text'");
- }
- };
- };
- writer.write("some sample text");
- }
-
- function fail(error) {
- console.log(error.code);
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>Write File</p>
- </body>
- </html>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/flags/flags.md
----------------------------------------------------------------------
diff --git a/docs/flags/flags.md b/docs/flags/flags.md
deleted file mode 100644
index 504f323..0000000
--- a/docs/flags/flags.md
+++ /dev/null
@@ -1,49 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-Flags
-=====
-
-Supplies arguments to the `DirectoryEntry` object's `getFile()` and
-`getDirectory()` methods, which look up or create files and
-directories, respectively.
-
-Properties
-----------
-
-- __create__: Indicates that the file or directory should be created if it does not already exist. _(boolean)_
-- __exclusive__: Has has no effect by itself, but when used with `create` causes the file or directory creation to fail if the target path already exists. _(boolean)_
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-Quick Example
--------------
-
- // Get the data directory, creating it if it doesn't exist.
- dataDir = fileSystem.root.getDirectory("data", {create: true});
-
- // Create the lock file, if and only if it doesn't exist.
- lockFile = dataDir.getFile("lockfile.txt", {create: true, exclusive: true});
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/localfilesystem/localfilesystem.md
----------------------------------------------------------------------
diff --git a/docs/localfilesystem/localfilesystem.md b/docs/localfilesystem/localfilesystem.md
deleted file mode 100644
index 2b933c9..0000000
--- a/docs/localfilesystem/localfilesystem.md
+++ /dev/null
@@ -1,110 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-LocalFileSystem
-===============
-
-This object provides a way to obtain root file systems.
-
-Methods
-----------
-
-- __requestFileSystem__: Requests a filesystem. _(Function)_
-- __resolveLocalFileSystemURI__: Retrieve a `DirectoryEntry` or `FileEntry` using local URI. _(Function)_
-
-Constants
----------
-
-- `LocalFileSystem.PERSISTENT`: Used for storage that should not be removed by the user agent without application or user permission.
-- `LocalFileSystem.TEMPORARY`: Used for storage with no guarantee of persistence.
-
-Details
--------
-
-The `LocalFileSystem` object methods are defined on the `window` object.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-Request File System Quick Example
----------------------------------
-
- function onSuccess(fileSystem) {
- console.log(fileSystem.name);
- }
-
- // request the persistent file system
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
-
-Resolve Local File System URI Quick Example
--------------------------------------------
-
- function onSuccess(fileEntry) {
- console.log(fileEntry.name);
- }
-
- window.resolveLocalFileSystemURI("file:///example.txt", onSuccess, onError);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Local File System Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for device API libraries to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // device APIs are available
- //
- function onDeviceReady() {
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
- window.resolveLocalFileSystemURI("file:///example.txt", onResolveSuccess, fail);
- }
-
- function onFileSystemSuccess(fileSystem) {
- console.log(fileSystem.name);
- }
-
- function onResolveSuccess(fileEntry) {
- console.log(fileEntry.name);
- }
-
- function fail(evt) {
- console.log(evt.target.error.code);
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>Local File System</p>
- </body>
- </html>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/c8480221/docs/metadata/metadata.md
----------------------------------------------------------------------
diff --git a/docs/metadata/metadata.md b/docs/metadata/metadata.md
deleted file mode 100644
index bfa3a46..0000000
--- a/docs/metadata/metadata.md
+++ /dev/null
@@ -1,54 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-Metadata
-==========
-
-An interface that supplies information about the state of a file or directory.
-
-Properties
-----------
-
-- __modificationTime__: The time when the file or directory was last modified. _(Date)_
-
-Details
--------
-
-The `Metadata` object represents information about the state of a file
-or directory. Calling a `DirectoryEntry` or `FileEntry` object's
-`getMetadata()` method results in a `Metadata` instance.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Windows 8
-
-Quick Example
--------------
-
- function win(metadata) {
- console.log("Last Modified: " + metadata.modificationTime);
- }
-
- // Request the metadata object for this entry
- entry.getMetadata(win, null);
[45/50] git commit: Merge branch 'dev' of
github.com:Zaspire/cordova-plugin-file into dev
Posted by st...@apache.org.
Merge branch 'dev' of github.com:Zaspire/cordova-plugin-file into dev
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/e3d9ac12
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/e3d9ac12
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/e3d9ac12
Branch: refs/heads/master
Commit: e3d9ac12becaf8fc12d26b932121b464905a7349
Parents: aa23cf4 7544f3c
Author: Steven Gill <st...@gmail.com>
Authored: Thu Jan 30 16:02:36 2014 -0800
Committer: Steven Gill <st...@gmail.com>
Committed: Thu Jan 30 16:02:36 2014 -0800
----------------------------------------------------------------------
plugin.xml | 3 +++
www/ubuntu/DirectoryEntry.js | 26 ++++++++++++++++++++++++++
www/ubuntu/FileWriter.js | 7 ++++++-
3 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[32/50] git commit: Android: Expose filePlugin getter so that other
plugins can register filesystems
Posted by st...@apache.org.
Android: Expose filePlugin getter so that other plugins can register filesystems
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/a6575308
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a6575308
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a6575308
Branch: refs/heads/master
Commit: a6575308dcfe73addfa1a93158cb533268f93ef0
Parents: 6a0e2a0
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Jan 23 11:02:22 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 23 11:02:22 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a6575308/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index cfefd53..ac24413 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -119,11 +119,15 @@ public class FileUtils extends CordovaPlugin {
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
- filePlugin = this;
+ FileUtils.filePlugin = this;
}
}
- private Filesystem filesystemForURL(LocalFilesystemURL localURL) {
+ public static FileUtils getFilePlugin() {
+ return filePlugin;
+ }
+
+ private Filesystem filesystemForURL(LocalFilesystemURL localURL) {
if (localURL == null) return null;
return filesystemForName(localURL.filesystemName);
}
@@ -736,8 +740,8 @@ public class FileUtils extends CordovaPlugin {
public static JSONObject getEntry(File file) throws JSONException {
JSONObject entry;
- if (filePlugin != null) {
- for (Filesystem fs:filePlugin.filesystems) {
+ if (getFilePlugin() != null) {
+ for (Filesystem fs:getFilePlugin().filesystems) {
entry = fs.makeEntryForFile(file);
if (entry != null) {
return entry;
[16/50] git commit: Android: Refactor File API
Posted by st...@apache.org.
Android: Refactor File API
Also gets content file copying working
Promote Filesystem interface to base class
Remove duplicated code; push to Filesystem class
Stream file output where possible between methods
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/eaeb5981
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/eaeb5981
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/eaeb5981
Branch: refs/heads/master
Commit: eaeb598124c01176c1c9191910b5761e56c00904
Parents: e7f83cb
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jan 8 13:24:50 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 9 14:03:38 2014 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 148 +++++++++++++++++----------
src/android/FileUtils.java | 34 +++++--
src/android/Filesystem.java | 167 +++++++++++++++++++++++++++----
src/android/LocalFilesystem.java | 143 +++++++-------------------
src/android/LocalFilesystemURL.java | 7 +-
src/android/ReadFileCallback.java | 7 --
6 files changed, 308 insertions(+), 198 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 03a1939..535a2fe 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -1,26 +1,30 @@
package org.apache.cordova.file;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
+import java.io.OutputStream;
import org.apache.cordova.CordovaInterface;
+import org.apache.cordova.CordovaResourceApi;
+import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentResolver;
import android.database.Cursor;
+import android.net.Uri;
import android.provider.MediaStore;
-public class ContentFilesystem implements Filesystem {
+public class ContentFilesystem extends Filesystem {
private CordovaInterface cordova;
+ private CordovaResourceApi resourceApi;
- public ContentFilesystem(CordovaInterface cordova) {
+ public ContentFilesystem(CordovaInterface cordova, CordovaWebView webView) {
this.cordova = cordova;
+ this.resourceApi = new CordovaResourceApi(webView.getContext(), webView.pluginManager);
}
@Override
@@ -41,23 +45,37 @@ public class ContentFilesystem implements Filesystem {
throw new IOException();
}
try {
- JSONObject entry = new JSONObject();
- entry.put("isFile", fp.isFile());
- entry.put("isDirectory", fp.isDirectory());
- entry.put("name", fp.getName());
- entry.put("fullPath", "file://" + fp.getAbsolutePath());
- // The file system can't be specified, as it would lead to an infinite loop.
- entry.put("filesystem", FileUtils.APPLICATION);
- return entry;
+ return makeEntryForPath(inputURL.fullPath, inputURL.filesystemType, fp.isDirectory());
} catch (JSONException e) {
throw new IOException();
}
}
-
- @Override
+
+ @Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
- String fileName, JSONObject options, boolean directory) throws IOException {
- throw new IOException("Cannot create content url");
+ String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException {
+ if (options != null) {
+ if (options.optBoolean("create")) {
+ throw new IOException("Cannot create content url");
+ }
+ }
+ LocalFilesystemURL requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, fileName));
+ File fp = new File(this.filesystemPathForURL(requestedURL));
+ if (!fp.exists()) {
+ throw new FileNotFoundException("path does not exist");
+ }
+ if (directory) {
+ if (fp.isFile()) {
+ throw new TypeMismatchException("path doesn't exist or is file");
+ }
+ } else {
+ if (fp.isDirectory()) {
+ throw new TypeMismatchException("path doesn't exist or is directory");
+ }
+ }
+ // Return the directory
+ return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemType, directory);
+
}
@Override
@@ -93,55 +111,72 @@ public class ContentFilesystem implements Filesystem {
@Override
public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @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);
+ String path = filesystemPathForURL(inputURL);
+ if (path == null) {
+ throw new FileNotFoundException();
+ }
+ File file = new File(path);
+ JSONObject metadata = new JSONObject();
+ try {
+ metadata.put("size", file.length());
+ metadata.put("type", resourceApi.getMimeType(inputURL.URL));
+ metadata.put("name", file.getName());
+ metadata.put("fullPath", inputURL.fullPath);
+ metadata.put("lastModifiedDate", file.lastModified());
+ } catch (JSONException e) {
+ return null;
+ }
+ return metadata;
}
@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move)
- throws IOException, InvalidModificationException, JSONException,
- NoModificationAllowedException, FileExistsException {
- // TODO Auto-generated method stub
- return null;
+ throws IOException, InvalidModificationException, JSONException,
+ NoModificationAllowedException, FileExistsException {
+ if (LocalFilesystem.class.isInstance(srcFs)) {
+ /* Same FS, we can shortcut with CordovaResourceApi operations */
+ // Figure out where we should be copying to
+ final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL);
+
+ OutputStream os = resourceApi.openOutputStream(destURL.URL);
+ CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcURL.URL);
+ if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
+ throw new NoModificationAllowedException("Cannot move file at source URL");
+ }
+ try {
+ resourceApi.copyResource(ofrr, os);
+ } catch (IOException e) {
+ throw new IOException("Cannot read file at source URL");
+ }
+ if (move) {
+ srcFs.removeFileAtLocalURL(srcURL);
+ }
+ return makeEntryForURL(destinationURL, false);
+ } else {
+ // Need to copy the hard way
+ return super.copyFileToURL(destURL, newName, srcFs, srcURL, move);
+ }
}
+
@Override
- public void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ public void readFileAtURL(LocalFilesystemURL inputURL, long start, long end,
ReadFileCallback readFileCallback) throws IOException {
- int numBytesToRead = end - start;
- byte[] bytes = new byte[numBytesToRead];
- String contentType;
-
- File file = new File(this.filesystemPathForURL(inputURL));
- contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
-
- InputStream inputStream = new FileInputStream(file);
- int numBytesRead = 0;
+ CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(inputURL.URL);
+ if (end < 0) {
+ end = ofrr.length;
+ }
+ long numBytesToRead = end - start;
try {
if (start > 0) {
- inputStream.skip(start);
- }
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ ofrr.inputStream.skip(start);
}
+ LimitedInputStream inputStream = new LimitedInputStream(ofrr.inputStream, numBytesToRead);
+ readFileCallback.handleData(inputStream, ofrr.mimeType);
} finally {
- inputStream.close();
+ ofrr.inputStream.close();
}
- readFileCallback.handleData(bytes, contentType);
}
@Override
@@ -178,7 +213,7 @@ public class ContentFilesystem implements Filesystem {
@Override
public LocalFilesystemURL URLforFilesystemPath(String path) {
- // TODO Auto-generated method stub
+ // Returns null as we don't support reverse mapping back to content:// URLs
return null;
}
@@ -188,4 +223,11 @@ public class ContentFilesystem implements Filesystem {
File file = new File(path);
return file.exists();
}
-}
+
+ @Override
+ OutputStream getOutputStreamForURL(LocalFilesystemURL inputURL)
+ throws IOException {
+ OutputStream os = resourceApi.openOutputStream(inputURL.URL);
+ return os;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 20a2700..d1c1b59 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -20,7 +20,6 @@ package org.apache.cordova.file;
import android.net.Uri;
import android.os.Environment;
-import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
@@ -34,9 +33,11 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URLDecoder;
import java.util.ArrayList;
@@ -68,6 +69,7 @@ public class FileUtils extends CordovaPlugin {
public static int PERSISTENT = 1;
public static int RESOURCE = 2;
public static int APPLICATION = 3;
+ public static int CONTENT = 4;
// This field exists only to support getEntry, below, which has been deprecated
private static FileUtils filePlugin;
@@ -99,8 +101,9 @@ public class FileUtils extends CordovaPlugin {
fp.mkdirs();
this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
- this.filesystems.add(null);
- this.filesystems.add(new ContentFilesystem(cordova));
+ this.filesystems.add(null); // Hold for 'resource' FS
+ this.filesystems.add(null); // Hold for 'application' FS
+ this.filesystems.add(new ContentFilesystem(cordova, webView));
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
@@ -764,22 +767,35 @@ public class FileUtils extends CordovaPlugin {
throw new MalformedURLException("No installed handlers for this URL");
}
- fs.readFileAtURL(inputURL, start, end, new ReadFileCallback() {
- public void handleData(byte[] bytes, String contentType) {
+ fs.readFileAtURL(inputURL, start, end, new Filesystem.ReadFileCallback() {
+ public void handleData(InputStream inputStream, String contentType) {
try {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ final int BUFFER_SIZE = 8192;
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ for (;;) {
+ int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE);
+
+ if (bytesRead <= 0) {
+ break;
+ }
+ os.write(buffer, 0, bytesRead);
+ }
+
PluginResult result;
switch (resultType) {
case PluginResult.MESSAGE_TYPE_STRING:
- result = new PluginResult(PluginResult.Status.OK, new String(bytes, encoding));
+ result = new PluginResult(PluginResult.Status.OK, os.toString(encoding));
break;
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
- result = new PluginResult(PluginResult.Status.OK, bytes);
+ result = new PluginResult(PluginResult.Status.OK, os.toByteArray());
break;
case PluginResult.MESSAGE_TYPE_BINARYSTRING:
- result = new PluginResult(PluginResult.Status.OK, bytes, true);
+ result = new PluginResult(PluginResult.Status.OK, os.toByteArray(), true);
break;
default: // Base64.
- byte[] base64 = Base64.encode(bytes, Base64.NO_WRAP);
+ byte[] base64 = Base64.encode(os.toByteArray(), Base64.NO_WRAP);
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
result = new PluginResult(PluginResult.Status.OK, s);
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index ba2c7bd..1f869c9 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -1,47 +1,174 @@
package org.apache.cordova.file;
import java.io.FileNotFoundException;
+import java.io.FilterInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
-import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-public interface Filesystem {
+public abstract class Filesystem {
- JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+ public interface ReadFileCallback {
+ public void handleData(InputStream inputStream, String contentType) throws IOException;
+ }
- JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String fileName,
- JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
+ public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir)
+ throws JSONException {
+ JSONObject entry = new JSONObject();
- boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException, NoModificationAllowedException;
+ int end = path.endsWith("/") ? 1 : 0;
+ String[] parts = path.substring(0,path.length()-end).split("/");
+ String name = parts[parts.length-1];
+ entry.put("isFile", !isDir);
+ entry.put("isDirectory", isDir);
+ entry.put("name", name);
+ entry.put("fullPath", path);
+ // The file system can't be specified, as it would lead to an infinite loop,
+ // but the filesystem type can
+ entry.put("filesystem", fsType);
- boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException, NoModificationAllowedException;
+ return entry;
- JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+ }
- JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+ public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir) throws JSONException {
+ return makeEntryForPath(inputURL.fullPath, inputURL.filesystemType, isDir);
+ }
- JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException;
+ abstract JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
- JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
- Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException;
+ abstract JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String fileName,
+ JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
- void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ abstract boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException, NoModificationAllowedException;
+
+ abstract boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) throws FileExistsException, NoModificationAllowedException;
+
+ abstract JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
+ abstract JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
+ 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);
+ }
+
+ protected LocalFilesystemURL makeDestinationURL(String newName, LocalFilesystemURL srcURL, LocalFilesystemURL destURL) {
+ // I know this looks weird but it is to work around a JSON bug.
+ if ("null".equals(newName) || "".equals(newName)) {
+ newName = srcURL.URL.getLastPathSegment();;
+ }
+
+ String newDest = destURL.URL.toString();
+ if (newDest.endsWith("/")) {
+ newDest = newDest + newName;
+ } else {
+ newDest = newDest + "/" + newName;
+ }
+ return new LocalFilesystemURL(newDest);
+ }
+
+ /* Read a source URL (possibly from a different filesystem, srcFs,) and copy it to
+ * the destination URL on this filesystem, optionally with a new filename.
+ * If move is true, then this method should either perform an atomic move operation
+ * or remove the source file when finished.
+ */
+ JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
+ Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
+ // This is "the hard way" -- transfer data between arbitrary filesystem urls/
+ // Gets an input stream from src, and writes its contents to an output stream
+ // from dest.
+
+ // First, check to see that we can do it
+ if (!move || srcFs.canRemoveFileAtLocalURL(srcURL)) {
+ final LocalFilesystemURL destination = makeDestinationURL(newName, srcURL, destURL);
+ srcFs.readFileAtURL(srcURL, 0, -1, new ReadFileCallback() {
+ public void handleData(InputStream inputStream, String contentType) throws IOException {
+ if (inputStream != null) {
+ //write data to file
+ OutputStream os = getOutputStreamForURL(destination);
+ final int BUFFER_SIZE = 8192;
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ for (;;) {
+ int bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE);
+
+ if (bytesRead <= 0) {
+ break;
+ }
+ os.write(buffer, 0, bytesRead);
+ }
+ os.close();
+ } else {
+ throw new IOException("Cannot read file at source URL");
+ }
+ }
+ });
+ if (move) {
+ // Delete original
+ srcFs.removeFileAtLocalURL(srcURL);
+ }
+ return makeEntryForURL(destination, false);
+ } else {
+ throw new NoModificationAllowedException("Cannot move file at source URL");
+ }
+ }
+
+ abstract OutputStream getOutputStreamForURL(LocalFilesystemURL inputURL) throws IOException;
+
+ abstract void readFileAtURL(LocalFilesystemURL inputURL, long start, long end,
ReadFileCallback readFileCallback) throws IOException;
- long writeToFileAtURL(LocalFilesystemURL inputURL, String data, int offset,
+ abstract long writeToFileAtURL(LocalFilesystemURL inputURL, String data, int offset,
boolean isBinary) throws NoModificationAllowedException, IOException;
- long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
+ abstract long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
throws IOException, NoModificationAllowedException;
// This method should return null if filesystem urls cannot be mapped to paths
- String filesystemPathForURL(LocalFilesystemURL url);
-
- LocalFilesystemURL URLforFilesystemPath(String path);
-
- boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL);
+ abstract String filesystemPathForURL(LocalFilesystemURL url);
+
+ abstract LocalFilesystemURL URLforFilesystemPath(String path);
+
+ abstract boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL);
+
+ protected class LimitedInputStream extends FilterInputStream {
+ long numBytesToRead;
+ public LimitedInputStream(InputStream in, long numBytesToRead) {
+ super(in);
+ this.numBytesToRead = numBytesToRead;
+ }
+ @Override
+ public int read() throws IOException {
+ if (numBytesToRead <= 0) {
+ return -1;
+ }
+ numBytesToRead--;
+ return in.read();
+ }
+ @Override
+ public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
+ if (numBytesToRead <= 0) {
+ return -1;
+ }
+ int bytesToRead = byteCount;
+ if (byteCount > numBytesToRead) {
+ bytesToRead = (int)numBytesToRead; // Cast okay; long is less than int here.
+ }
+ int numBytesRead = in.read(buffer, byteOffset, bytesToRead);
+ numBytesToRead -= numBytesRead;
+ return numBytesRead;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 6c16e45..f0d919f 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
@@ -18,7 +19,7 @@ import org.json.JSONObject;
import android.util.Base64;
import android.net.Uri;
-public class LocalFilesystem implements Filesystem {
+public class LocalFilesystem extends Filesystem {
private String name;
private String fsRoot;
@@ -55,24 +56,6 @@ public class LocalFilesystem implements Filesystem {
return null;
}
- public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws JSONException {
- JSONObject entry = new JSONObject();
-
- int end = path.endsWith("/") ? 1 : 0;
- String[] parts = path.substring(0,path.length()-end).split("/");
- String name = parts[parts.length-1];
- entry.put("isFile", !isDir);
- entry.put("isDirectory", isDir);
- entry.put("name", name);
- entry.put("fullPath", path);
- // The file system can't be specified, as it would lead to an infinite loop,
- // but the filesystem type can
- entry.put("filesystem", fsType);
-
- return entry;
-
- }
-
public JSONObject makeEntryForFile(File file, int fsType) throws JSONException {
String path = this.fullPathForFilesystemPath(file.getAbsolutePath());
if (path != null) {
@@ -240,18 +223,6 @@ 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);
- }
-
/**
* Check to see if the user attempted to copy an entry into its parent without changing its name,
* or attempted to copy a directory into a directory that it contains directly or indirectly.
@@ -272,31 +243,6 @@ public class LocalFilesystem implements Filesystem {
return false;
}
-
- /**
- * Creates the destination File object based on name passed in
- *
- * @param newName for the file directory to be called, if null use existing file name
- * @param fp represents the source file
- * @param destination represents the destination file
- * @return a File object that represents the destination
- */
- private File createDestination(String newName, String oldName, File destination) {
- File destFile = null;
-
- // I know this looks weird but it is to work around a JSON bug.
- if ("null".equals(newName) || "".equals(newName)) {
- newName = null;
- }
-
- if (newName != null) {
- destFile = new File(destination.getAbsolutePath() + File.separator + newName);
- } else {
- destFile = new File(destination.getAbsolutePath() + File.separator + oldName);
- }
- return destFile;
- }
-
/**
* Copy a file
*
@@ -473,92 +419,71 @@ public class LocalFilesystem implements Filesystem {
throw new FileNotFoundException("The source does not exist");
}
- // Figure out where we should be copying to
- String originalName = srcURL.URL.getLastPathSegment();
- final File destination = createDestination(newName, originalName, destinationDir);
-
if (LocalFilesystem.class.isInstance(srcFs)) {
/* Same FS, we can shortcut with NSFileManager operations */
+
+ // Figure out where we should be copying to
+ final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL);
+
String srcFilesystemPath = this.filesystemPathForURL(srcURL);
- File source = new File(srcFilesystemPath);
+ File sourceFile = new File(srcFilesystemPath);
+ String destFilesystemPath = this.filesystemPathForURL(destinationURL);
+ File destinationFile = new File(destFilesystemPath);
- if (!source.exists()) {
+ if (!sourceFile.exists()) {
// The file/directory we are copying doesn't exist so we should fail.
throw new FileNotFoundException("The source does not exist");
}
// Check to see if source and destination are the same file
- if (source.getAbsolutePath().equals(destination.getAbsolutePath())) {
+ if (sourceFile.getAbsolutePath().equals(destinationFile.getAbsolutePath())) {
throw new InvalidModificationException("Can't copy a file onto itself");
}
- if (source.isDirectory()) {
+ if (sourceFile.isDirectory()) {
if (move) {
- return moveDirectory(source, destination, destURL.filesystemType);
+ return moveDirectory(sourceFile, destinationFile, destURL.filesystemType);
} else {
- return copyDirectory(source, destination, destURL.filesystemType);
+ return copyDirectory(sourceFile, destinationFile, destURL.filesystemType);
}
} else {
if (move) {
- return moveFile(source, destination, destURL.filesystemType);
+ return moveFile(sourceFile, destinationFile, destURL.filesystemType);
} else {
- return copyFile(source, destination, destURL.filesystemType);
+ return copyFile(sourceFile, destinationFile, destURL.filesystemType);
}
}
} else {
// Need to copy the hard way
- // First, check to see that we can do it
- if (!move || srcFs.canRemoveFileAtLocalURL(srcURL)) {
- srcFs.readFileAtURL(srcURL, 0, -1, new ReadFileCallback() {
- public void handleData(byte[] data, String contentType) throws IOException {
- if (data != null) {
- //write data to file
- FileOutputStream os = new FileOutputStream(destination);
- os.write(data);
- os.close();
- } else {
- throw new IOException("Cannot read file at source URL");
- }
- }
- });
- if (move) {
- // Delete original
- srcFs.removeFileAtLocalURL(srcURL);
- }
- return makeEntryForFile(destination, destURL.filesystemType);
- } else {
- throw new NoModificationAllowedException("Cannot move file at source URL");
- }
+ return super.copyFileToURL(destURL, newName, srcFs, srcURL, move);
}
}
@Override
- public void readFileAtURL(LocalFilesystemURL inputURL, int start, int end,
+ public void readFileAtURL(LocalFilesystemURL inputURL, long start, long end,
ReadFileCallback readFileCallback) throws IOException {
- int numBytesToRead = end - start;
- byte[] bytes = new byte[numBytesToRead];
- String contentType;
-
File file = new File(this.filesystemPathForURL(inputURL));
- contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
+ String contentType = FileHelper.getMimeTypeForExtension(file.getAbsolutePath());
- InputStream inputStream = new FileInputStream(file);
- int numBytesRead = 0;
+ if (end < 0) {
+ end = file.length();
+ }
+ long numBytesToRead = end - start;
+
+ InputStream rawInputStream = new FileInputStream(file);
try {
if (start > 0) {
- inputStream.skip(start);
- }
- while (numBytesToRead > 0 && (numBytesRead = inputStream.read(bytes, numBytesRead, numBytesToRead)) >= 0) {
- numBytesToRead -= numBytesRead;
+ rawInputStream.skip(start);
}
+ LimitedInputStream inputStream = new LimitedInputStream(rawInputStream, numBytesToRead);
+ readFileCallback.handleData(inputStream, contentType);
} finally {
- inputStream.close();
+ rawInputStream.close();
}
- readFileCallback.handleData(bytes, contentType);
}
-
+
@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
@@ -630,4 +555,12 @@ public class LocalFilesystem implements Filesystem {
return file.exists();
}
+ @Override
+ OutputStream getOutputStreamForURL(LocalFilesystemURL inputURL) throws FileNotFoundException {
+ String path = filesystemPathForURL(inputURL);
+ File file = new File(path);
+ FileOutputStream os = new FileOutputStream(file);
+ return os;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index 0dc547e..1065382 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -24,8 +24,8 @@ public class LocalFilesystemURL {
if (fsType == FileUtils.PERSISTENT) {
return URL.getPath().substring(11);
}
- if (fsType == FileUtils.APPLICATION) {
- return URL.getPath();
+ if (fsType == FileUtils.CONTENT) {
+ return '/' + URL.getHost() + URL.getPath();
}
return null;
}
@@ -41,7 +41,7 @@ public class LocalFilesystemURL {
}
}
} else if ("content".equals(URL.getScheme())) {
- return FileUtils.APPLICATION;
+ return FileUtils.CONTENT;
}
return -1;
}
@@ -50,5 +50,4 @@ public class LocalFilesystemURL {
this(Uri.parse(strURL));
}
-
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaeb5981/src/android/ReadFileCallback.java
----------------------------------------------------------------------
diff --git a/src/android/ReadFileCallback.java b/src/android/ReadFileCallback.java
deleted file mode 100644
index b8ba02d..0000000
--- a/src/android/ReadFileCallback.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.apache.cordova.file;
-
-import java.io.IOException;
-
-public interface ReadFileCallback {
- public void handleData(byte[] data, String contentType) throws IOException;
-}
[31/50] git commit: Fix typos in deprecation message
Posted by st...@apache.org.
Fix typos in deprecation message
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/6a0e2a0f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/6a0e2a0f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/6a0e2a0f
Branch: refs/heads/master
Commit: 6a0e2a0f49d44453a1191bcbe7dae575966634f0
Parents: ca3813c
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Jan 23 09:53:16 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 23 09:53:16 2014 -0500
----------------------------------------------------------------------
www/resolveLocalFileSystemURI.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/6a0e2a0f/www/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/resolveLocalFileSystemURI.js b/www/resolveLocalFileSystemURI.js
index 06090c2..6fef4b1 100644
--- a/www/resolveLocalFileSystemURI.js
+++ b/www/resolveLocalFileSystemURI.js
@@ -64,6 +64,6 @@ module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorC
exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
};
module.exports.resolveLocalFileSystemURI = function() {
- console.log("resolveLocalfileSystemURI is deprecated. Please call reolvelLocalFileSystemURL instead");
+ console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
module.exports.resolveLocalFileSystemURL.apply(this, arguments);
};
[39/50] git commit: CB-5915: Create documents directories if they
don't exist
Posted by st...@apache.org.
CB-5915: Create documents directories if they don't exist
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/d5478e56
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/d5478e56
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/d5478e56
Branch: refs/heads/master
Commit: d5478e561277a80d54021c5ad5112a0b2bf06e6a
Parents: b68e127
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 11:42:21 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 11:42:21 2014 -0500
----------------------------------------------------------------------
src/ios/CDVFile.m | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d5478e56/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 847f858..b1925d0 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -198,9 +198,24 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
}
- [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
+ NSError *error;
+ if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appTempPath
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error]) {
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"temporary" root:self.appTempPath]];
+ } else {
+ NSLog(@"Unable to create temporary directory: %@", error);
+ }
if ([location isEqualToString:@"library"]) {
- [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
+ if ([[NSFileManager defaultManager] createDirectoryAtPath:self.appLibraryPath
+ withIntermediateDirectories:YES
+ attributes:nil
+ error:&error]) {
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.appLibraryPath]];
+ } else {
+ NSLog(@"Unable to create library directory: %@", error);
+ }
} else {
// Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
/*
@@ -238,7 +253,6 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
self.rootDocsPath = [paths objectAtIndex:0];
self.appDocsPath = [self.rootDocsPath stringByAppendingPathComponent:@"files"];
-
}
return self;
[23/50] git commit: Change default FS URL scheme to "cdvfile"
Posted by st...@apache.org.
Change default FS URL scheme to "cdvfile"
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/9d528160
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9d528160
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9d528160
Branch: refs/heads/master
Commit: 9d528160e42d57c6b99afb3fef97a5b3215b9acb
Parents: 73dbfb6
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Jan 13 09:34:01 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Jan 13 10:10:47 2014 -0500
----------------------------------------------------------------------
src/android/LocalFilesystemURL.java | 2 +-
src/ios/CDVFile.m | 2 +-
www/android/FileSystem.js | 2 +-
www/ios/FileSystem.js | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9d528160/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index a3aade8..2aec395 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -4,7 +4,7 @@ import android.net.Uri;
public class LocalFilesystemURL {
- public static final String FILESYSTEM_PROTOCOL = "filesystem";
+ public static final String FILESYSTEM_PROTOCOL = "cdvfile";
public static final int TEMPORARY = 0;
public static final int PERSISTENT = 1;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9d528160/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 7bc39b9..500acb1 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -30,7 +30,7 @@ extern NSString * const NSURLIsExcludedFromBackupKey __attribute__((weak_import)
NSString* const NSURLIsExcludedFromBackupKey = @"NSURLIsExcludedFromBackupKey";
#endif
-NSString* const kCDVFilesystemURLPrefix = @"filesystem";
+NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@implementation CDVFilesystemURL
@synthesize url=_url;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9d528160/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index d0db194..73332f8 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -19,7 +19,7 @@
*
*/
-FILESYSTEM_PROTOCOL = "filesystem";
+FILESYSTEM_PROTOCOL = "cdvfile";
module.exports = {
__format__: function(fullPath) {
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9d528160/www/ios/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ios/FileSystem.js b/www/ios/FileSystem.js
index 2099a99..b11d58f 100644
--- a/www/ios/FileSystem.js
+++ b/www/ios/FileSystem.js
@@ -19,7 +19,7 @@
*
*/
-FILESYSTEM_PROTOCOL = "filesystem";
+FILESYSTEM_PROTOCOL = "cdvfile";
module.exports = {
__format__: function(fullPath) {
[28/50] git commit: [ubuntu] adopt to recent changes
Posted by st...@apache.org.
[ubuntu] adopt to recent changes
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/7544f3c0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/7544f3c0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/7544f3c0
Branch: refs/heads/master
Commit: 7544f3c01215e9ab0afcca02b4b0ffc80d069acf
Parents: 3fe44cf
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Tue Jan 21 14:35:38 2014 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Tue Jan 21 14:35:38 2014 +0400
----------------------------------------------------------------------
plugin.xml | 3 +++
www/ubuntu/DirectoryEntry.js | 26 ++++++++++++++++++++++++++
www/ubuntu/FileWriter.js | 7 ++++++-
3 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7544f3c0/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index f5d215a..93be870 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -143,6 +143,9 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<js-module src="www/ubuntu/Entry.js" name="Entry1">
<merges target="window.Entry" />
</js-module>
+ <js-module src="www/ubuntu/DirectoryEntry.js" name="DirectoryEntry1">
+ <merges target="window.DirectoryEntry" />
+ </js-module>
<js-module src="www/ubuntu/FileWriter.js" name="FileWriter1">
<merges target="window.FileWriter" />
</js-module>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7544f3c0/www/ubuntu/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/www/ubuntu/DirectoryEntry.js b/www/ubuntu/DirectoryEntry.js
new file mode 100644
index 0000000..80949f0
--- /dev/null
+++ b/www/ubuntu/DirectoryEntry.js
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+ createReader: function() {
+ return new DirectoryReader(this.fullPath);
+ }
+};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/7544f3c0/www/ubuntu/FileWriter.js
----------------------------------------------------------------------
diff --git a/www/ubuntu/FileWriter.js b/www/ubuntu/FileWriter.js
index 52a17fc..a75506b 100644
--- a/www/ubuntu/FileWriter.js
+++ b/www/ubuntu/FileWriter.js
@@ -70,6 +70,11 @@ function write(data) {
data = binary;
}
+ var prefix = "file://localhost";
+ var path = this.localURL;
+ if (path.substr(0, prefix.length) == prefix) {
+ path = path.substr(prefix.length);
+ }
// Write file
exec(
// Success callback
@@ -120,7 +125,7 @@ function write(data) {
if (typeof me.onwriteend === "function") {
me.onwriteend(new ProgressEvent("writeend", {"target":me}));
}
- }, "File", "write", [this.fileName, data, this.position, isBinary]);
+ }, "File", "write", [path, data, this.position, isBinary]);
};
module.exports = {
[42/50] git commit: Add constuctor params to FileUploadResult related
to CB-2421
Posted by st...@apache.org.
Add constuctor params to FileUploadResult related to CB-2421
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/5e4a8756
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/5e4a8756
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/5e4a8756
Branch: refs/heads/master
Commit: 5e4a8756f307d2db10cfdea1ea1d5aa70d2ce460
Parents: 2bfa075
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Jan 28 15:02:05 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Jan 28 15:02:05 2014 -0800
----------------------------------------------------------------------
www/FileUploadResult.js | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/5e4a8756/www/FileUploadResult.js
----------------------------------------------------------------------
diff --git a/www/FileUploadResult.js b/www/FileUploadResult.js
index 294995f..4f2e33e 100644
--- a/www/FileUploadResult.js
+++ b/www/FileUploadResult.js
@@ -23,10 +23,8 @@
* FileUploadResult
* @constructor
*/
-var FileUploadResult = function() {
- this.bytesSent = 0;
- this.responseCode = null;
- this.response = null;
-};
-
-module.exports = FileUploadResult;
+module.exports = function FileUploadResult(size, code, content) {
+ this.bytesSent = size;
+ this.responseCode = code;
+ this.response = content;
+ };
\ No newline at end of file
[38/50] git commit: CB-5916: Android: Fix unfortunate NPE in config
check
Posted by st...@apache.org.
CB-5916: Android: Fix unfortunate NPE in config check
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/b68e1278
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/b68e1278
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/b68e1278
Branch: refs/heads/master
Commit: b68e1278d038716728ab83ae9543bb52f2c58e04
Parents: 28c21bf
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 11:12:15 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 11:12:15 2014 -0500
----------------------------------------------------------------------
src/android/FileUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b68e1278/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index f9a36a7..415d0e2 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -102,7 +102,7 @@ public class FileUtils extends CordovaPlugin {
String packageName = activity.getPackageName();
String location = activity.getIntent().getStringExtra("androidpersistentfilelocation");
- if (!(location.equalsIgnoreCase("internal") || location.equalsIgnoreCase("compatibility"))) {
+ if (location == null || !(location.equalsIgnoreCase("internal") || location.equalsIgnoreCase("compatibility"))) {
Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
activity.finish();
}
[21/50] git commit: Android: Allow absolute paths on Entry.getFile /
Entry.getDirectory
Posted by st...@apache.org.
Android: Allow absolute paths on Entry.getFile / Entry.getDirectory
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/fc2fc56e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/fc2fc56e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/fc2fc56e
Branch: refs/heads/master
Commit: fc2fc56e2241ebda6d1f985fb09ec956511d3248
Parents: d8b728a
Author: Ian Clelland <ic...@chromium.org>
Authored: Sat Jan 11 09:46:46 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Sat Jan 11 09:46:46 2014 -0500
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/fc2fc56e/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index c16aefe..b64118b 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -107,7 +107,14 @@ public class LocalFilesystem extends Filesystem {
throw new EncodingException("This path has an invalid \":\" in it.");
}
- LocalFilesystemURL requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, fileName));
+ LocalFilesystemURL requestedURL;
+
+ // Check whether the supplied path is absolute or relative
+ if (path.startsWith("/")) {
+ requestedURL = URLforFilesystemPath(path);
+ } else {
+ requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, path));
+ }
File fp = new File(this.filesystemPathForURL(requestedURL));
[06/50] git commit: CB-5407: Fixes for ContentFilesystem
Posted by st...@apache.org.
CB-5407: Fixes for ContentFilesystem
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/a2b90737
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/a2b90737
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/a2b90737
Branch: refs/heads/master
Commit: a2b90737e6e1fcf089a4fe12a12f07426091577a
Parents: 83a867c
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Dec 13 10:52:20 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:16:37 2013 -0500
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 24 ++++++++++++++++++++----
src/android/FileUtils.java | 7 ++++++-
2 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a2b90737/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 4e5175b..b1d397e 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -9,6 +9,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.MediaStore;
@@ -108,9 +109,24 @@ public class ContentFilesystem implements Filesystem {
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
}
- @Override
- public String filesystemPathForURL(LocalFilesystemURL url) {
- return null;
- }
+ @Override
+ public String filesystemPathForURL(LocalFilesystemURL url) {
+ final String[] LOCAL_FILE_PROJECTION = { MediaStore.Images.Media.DATA };
+ ContentResolver contentResolver = this.cordova.getActivity().getContentResolver();
+ Cursor cursor = contentResolver.query(url.URL, LOCAL_FILE_PROJECTION, null, null, null);
+ if (cursor != null) {
+ try {
+ int columnIndex = cursor.getColumnIndex(LOCAL_FILE_PROJECTION[0]);
+ if (columnIndex != -1 && cursor.getCount() > 0) {
+ cursor.moveToFirst();
+ String path = cursor.getString(columnIndex);
+ return path;
+ }
+ } finally {
+ cursor.close();
+ }
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a2b90737/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 7e852b5..1ae7d0c 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -97,6 +97,7 @@ public class FileUtils extends CordovaPlugin {
fp.mkdirs();
this.filesystems.add(new LocalFilesystem(cordova, "temporary", tempRoot));
this.filesystems.add(new LocalFilesystem(cordova, "persistent", persistentRoot));
+ this.filesystems.add(null);
this.filesystems.add(new ContentFilesystem(cordova));
// Initialize static plugin reference for deprecated getEntry method
@@ -121,7 +122,11 @@ public class FileUtils extends CordovaPlugin {
if (fs == null) {
return null;
}
- return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+ String path = fs.filesystemPathForURL(inputURL);
+ if (path != null) {
+ return Uri.parse("file:///" + fs.filesystemPathForURL(inputURL));
+ }
+ return null;
} catch (IllegalArgumentException e) {
return null;
}
[33/50] git commit: iOS: Android: Allow third-party plugin
registration
Posted by st...@apache.org.
iOS: Android: Allow third-party plugin registration
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/590b9303
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/590b9303
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/590b9303
Branch: refs/heads/master
Commit: 590b9303fd29f5e6d9c2aaa6b1a720c61881a9f4
Parents: a657530
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Jan 23 14:14:33 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Jan 23 22:35:50 2014 -0500
----------------------------------------------------------------------
src/ios/CDVAssetLibraryFilesystem.h | 2 +
src/ios/CDVAssetLibraryFilesystem.m | 17 +++-
src/ios/CDVFile.h | 19 ++--
src/ios/CDVFile.m | 153 +++++++++++++++++++------------
src/ios/CDVLocalFilesystem.h | 1 -
src/ios/CDVLocalFilesystem.m | 17 ++--
6 files changed, 126 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVAssetLibraryFilesystem.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.h b/src/ios/CDVAssetLibraryFilesystem.h
index 295a3d8..e09e225 100644
--- a/src/ios/CDVAssetLibraryFilesystem.h
+++ b/src/ios/CDVAssetLibraryFilesystem.h
@@ -25,4 +25,6 @@ extern NSString* const kCDVAssetsLibraryScheme;
@interface CDVAssetLibraryFilesystem : NSObject<CDVFileSystem> {
}
+- (id) initWithName:(NSString *)name;
+
@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVAssetLibraryFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.m b/src/ios/CDVAssetLibraryFilesystem.m
index 09a5461..cca4038 100644
--- a/src/ios/CDVAssetLibraryFilesystem.m
+++ b/src/ios/CDVAssetLibraryFilesystem.m
@@ -29,6 +29,8 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
NSString* const kCDVAssetsLibraryScheme = @"assets-library";
@implementation CDVAssetLibraryFilesystem
+@synthesize name=_name;
+
- (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url
{
NSDictionary* entry = [self makeEntryForLocalURL:url];
@@ -36,10 +38,10 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
}
- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url {
- return [self makeEntryForPath:[url.url absoluteString] fileSystem:ASSETS_LIBRARY isDirectory:NO];
+ return [self makeEntryForPath:[url.url absoluteString] fileSystemName:self.name isDirectory:NO];
}
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
{
NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
NSString* lastPart = [fullPath lastPathComponent];
@@ -50,7 +52,8 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
[dirEntry setObject:[NSNumber numberWithBool:isDir] forKey:@"isDirectory"];
[dirEntry setObject:fullPath forKey:@"fullPath"];
[dirEntry setObject:lastPart forKey:@"name"];
- [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
+ [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ? 0 : 1)] forKey: @"filesystem"];
+ [dirEntry setObject:fsName forKey: @"filesystemName"];
return dirEntry;
}
@@ -83,6 +86,14 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
return mimeType;
}
+- (id)initWithName:(NSString *)name
+{
+ if (self) {
+ _name = name;
+ }
+ return self;
+}
+
- (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options
{
// return unsupported result for assets-library URLs
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 0693f68..85a76b0 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -40,16 +40,9 @@ enum CDVFileError {
};
typedef int CDVFileError;
-enum CDVFileSystemType {
- TEMPORARY = 0,
- PERSISTENT = 1,
- ASSETS_LIBRARY = 2,
-};
-typedef int CDVFileSystemType;
-
@interface CDVFilesystemURL : NSObject {
NSURL *_url;
- CDVFileSystemType _fileSystemType;
+ NSString *_fileSystemName;
NSString *_fullPath;
}
@@ -60,7 +53,7 @@ typedef int CDVFileSystemType;
@property (atomic) NSURL *url;
-@property (atomic) CDVFileSystemType fileSystemType;
+@property (atomic) NSString *fileSystemName;
@property (atomic) NSString *fullPath;
@end
@@ -85,6 +78,8 @@ typedef int CDVFileSystemType;
- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url;
+@property (nonatomic,strong) NSString *name;
+
@optional
- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;
- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path;
@@ -103,12 +98,16 @@ typedef int CDVFileSystemType;
}
- (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir;
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir;
- (NSDictionary *)makeEntryForURL:(NSURL *)URL;
- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
+/* Native Registration API */
+- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs;
+- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName;
+
/* Exec API */
- (void)requestFileSystem:(CDVInvokedUrlCommand*)command;
- (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command;
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 500acb1..f4f1cbb 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -34,7 +34,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@implementation CDVFilesystemURL
@synthesize url=_url;
-@synthesize fileSystemType=_fileSystemType;
+@synthesize fileSystemName=_fileSystemName;
@synthesize fullPath=_fullPath;
- (id) initWithString:(NSString *)strURL
@@ -50,7 +50,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
{
if ( self = [super init] ) {
_url = URL;
- _fileSystemType = [self filesystemTypeForLocalURI:URL];
+ _fileSystemName = [self filesystemNameForLocalURI:URL];
_fullPath = [self fullPathForLocalURI:URL];
}
return self;
@@ -60,20 +60,19 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
* IN
* NSString localURI
* OUT
- * int FileSystem type for this URI, or -1 if it is not recognized.
+ * NSString FileSystem Name for this URI, or nil if it is not recognized.
*/
-- (CDVFileSystemType)filesystemTypeForLocalURI:(NSURL *)uri
+- (NSString *)filesystemNameForLocalURI:(NSURL *)uri
{
if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"]) {
- if ([[uri path] hasPrefix:@"/temporary"]) {
- return TEMPORARY;
- } else if ([[uri path] hasPrefix:@"/persistent"]) {
- return PERSISTENT;
+ NSArray *pathComponents = [uri pathComponents];
+ if (pathComponents != nil && pathComponents.count > 1) {
+ return [pathComponents objectAtIndex:1];
}
} else if ([[uri scheme] isEqualToString:kCDVAssetsLibraryScheme]) {
- return ASSETS_LIBRARY;
+ return @"assets-library";
}
- return -1;
+ return nil;
}
/*
@@ -85,11 +84,13 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
*/
- (NSString *)fullPathForLocalURI:(NSURL *)uri
{
- int fsType = [self filesystemTypeForLocalURI:uri];
- if (fsType == TEMPORARY) {
- return [[uri path] substringFromIndex:10];
- } else if (fsType == PERSISTENT) {
- return [[uri path] substringFromIndex:11];
+ if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"]) {
+ NSString *path = [uri path];
+ NSRange slashRange = [path rangeOfString:@"/" options:0 range:NSMakeRange(1, path.length-1)];
+ if (slashRange.location == NSNotFound) {
+ return @"";
+ }
+ return [path substringFromIndex:slashRange.location];
}
return nil;
}
@@ -127,7 +128,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
- (void)startLoading
{
CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithURL:[[self request] URL]];
- CDVLocalFilesystem *fs = [filePlugin.fileSystems objectAtIndex:url.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [filePlugin filesystemForURL:url];
[fs readFileAtURL:url start:0 end:-1 callback:^void(NSData *data, NSString *mimetype, CDVFileError error) {
if (!error) {
NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url.url statusCode:200 HTTPVersion:@"HTTP/1.1"headerFields:@{@"Content-Type": mimetype}];
@@ -154,11 +155,39 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
@synthesize appDocsPath, appLibraryPath, appTempPath, persistentPath, temporaryPath, userHasAllowed, fileSystems=fileSystems_;
+- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
+ [fileSystems_ addObject:fs];
+}
+
+- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName
+{
+ if (self.fileSystems != nil) {
+ for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
+ if ([fs.name isEqualToString:fsName]) {
+ return fs;
+ }
+ }
+ }
+ return nil;
+
+}
+
+- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL {
+ if (localURL.fileSystemName == nil) return nil;
+ @try {
+ return [self fileSystemByName:localURL.fileSystemName];
+ }
+ @catch (NSException *e) {
+ return nil;
+ }
+}
+
- (id)initWithWebView:(UIWebView*)theWebView
{
self = (CDVFile*)[super initWithWebView:theWebView];
if (self) {
filePlugin = self;
+// @throw (@"Error!");
[NSURLProtocol registerClass:[CDVFilesystemURLProtocol class]];
fileSystems_ = [[NSMutableArray alloc] initWithCapacity:3];
@@ -175,26 +204,19 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
self.appDocsPath = [paths objectAtIndex:0];
- [fileSystems_ addObject:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths objectAtIndex:0]]];
+ [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths objectAtIndex:0]]];
self.persistentPath = [NSString stringWithFormat:@"/%@", [self.appDocsPath lastPathComponent]];
self.temporaryPath = [NSString stringWithFormat:@"/%@", [self.appTempPath lastPathComponent]];
// NSLog(@"docs: %@ - temp: %@", self.appDocsPath, self.appTempPath);
+
+ [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
+
}
return self;
}
-- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL {
- if (localURL.fileSystemType == -1) return nil;
- @try {
- return [self.fileSystems objectAtIndex:localURL.fileSystemType];
- }
- @catch (NSException *e) {
- return nil;
- }
-}
-
- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath
{
CDVFilesystemURL *localURL = nil;
@@ -249,9 +271,9 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
int type = [strType intValue];
CDVPluginResult* result = nil;
- if (type > 1) {
+ if (type > self.fileSystems.count) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:NOT_FOUND_ERR];
- NSLog(@"iOS only supports TEMPORARY and PERSISTENT file systems");
+ NSLog(@"No filesystem of type requested");
} else {
NSString* fullPath = @"/";
// check for avail space for size request
@@ -260,11 +282,17 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
if (pNumAvail && ([pNumAvail unsignedLongLongValue] < size)) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:QUOTA_EXCEEDED_ERR];
} else {
- NSMutableDictionary* fileSystem = [NSMutableDictionary dictionaryWithCapacity:2];
- [fileSystem setObject:(type == TEMPORARY ? kW3FileTemporary : kW3FilePersistent) forKey:@"name"];
- NSDictionary* dirEntry = [self makeEntryForPath:fullPath fileSystem:type isDirectory:YES];
- [fileSystem setObject:dirEntry forKey:@"root"];
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
+ NSObject<CDVFileSystem> *rootFs = [self.fileSystems objectAtIndex:type];
+ if (rootFs == nil) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:NOT_FOUND_ERR];
+ NSLog(@"No filesystem of type requested");
+ } else {
+ NSMutableDictionary* fileSystem = [NSMutableDictionary dictionaryWithCapacity:2];
+ [fileSystem setObject:rootFs.name forKey:@"name"];
+ NSDictionary* dirEntry = [self makeEntryForPath:fullPath fileSystemName:rootFs.name isDirectory:YES];
+ [fileSystem setObject:dirEntry forKey:@"root"];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
+ }
}
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -282,10 +310,10 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
* bool as NSNumber isFile
* NSString* name - last part of path
* NSString* fullPath
- * filesystem = FileSystem type -- actual filesystem will be created on the JS side if necessary, to avoid
+ * NSString* filesystemName - FileSystem name -- actual filesystem will be created on the JS side if necessary, to avoid
* creating circular reference (FileSystem contains DirectoryEntry which contains FileSystem.....!!)
*/
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
{
NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
NSString* lastPart = [fullPath lastPathComponent];
@@ -296,15 +324,15 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
[dirEntry setObject:[NSNumber numberWithBool:isDir] forKey:@"isDirectory"];
[dirEntry setObject:fullPath forKey:@"fullPath"];
[dirEntry setObject:lastPart forKey:@"name"];
- [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
-
+ [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ? 0 : 1)] forKey: @"filesystem"];
+ [dirEntry setObject:fsName forKey: @"filesystemName"];
return dirEntry;
}
- (NSDictionary *)makeEntryForURL:(NSURL *)URL
{
CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithURL:URL];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:fsURL.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:fsURL];
return [fs makeEntryForLocalURL:fsURL];
}
@@ -341,10 +369,10 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
} else {
inputURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
}
- if (inputURI != nil && inputURI.fileSystemType == -1) {
+ if (inputURI != nil && inputURI.fileSystemName == nil) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ENCODING_ERR];
} else {
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:inputURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:inputURI];
result = [fs entryForLocalURI:inputURI];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -415,7 +443,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSString* requestedPath = [command.arguments objectAtIndex:1];
NSDictionary* options = [command.arguments objectAtIndex:2 withDefault:nil];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:baseURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:baseURI];
CDVPluginResult* result = [fs getFileForURL:baseURI requestedPath:requestedPath options:options];
@@ -436,7 +464,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// arguments are URL encoded
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments objectAtIndex:0]];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
CDVPluginResult* result = [fs getParentForURL:localURI];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -451,7 +479,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// arguments
NSString* localURIstr = [command.arguments objectAtIndex:0];
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[fs getMetadataForURL:localURI callback:^(CDVPluginResult* result) {
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}];
@@ -467,7 +495,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// arguments
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments objectAtIndex:0]];
NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:nil];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
CDVPluginResult* result = [fs setMetadataForURL:localURI withObject:options];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -492,7 +520,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// error if try to remove top level (documents or tmp) dir
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
} else {
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
result = [fs removeFileAtURL:localURI];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -516,7 +544,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// error if try to remove top level (documents or tmp) dir
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
} else {
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
result = [fs recursiveRemoveFileAtURL:localURI];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -560,8 +588,8 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
CDVFilesystemURL* srcURL = [CDVFilesystemURL fileSystemURLWithString:srcURLstr];
CDVFilesystemURL* destURL = [CDVFilesystemURL fileSystemURLWithString:destURLstr];
- CDVLocalFilesystem *srcFs = [self.fileSystems objectAtIndex:srcURL.fileSystemType];
- CDVLocalFilesystem *destFs = [self.fileSystems objectAtIndex:destURL.fileSystemType];
+ NSObject<CDVFileSystem> *srcFs = [self filesystemForURL:srcURL];
+ NSObject<CDVFileSystem> *destFs = [self filesystemForURL:destURL];
// optional argument; use last component from srcFullPath if new name not provided
NSString* newName = ([arguments count] > 2) ? [arguments objectAtIndex:2] : [srcURL.url lastPathComponent];
@@ -583,7 +611,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// arguments
NSString* localURIstr = [command.arguments objectAtIndex:0];
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[fs getFileMetadataForURL:localURI callback:^(CDVPluginResult* result) {
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -593,7 +621,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
- (void)readEntries:(CDVInvokedUrlCommand*)command
{
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments objectAtIndex:0]];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
CDVPluginResult *result = [fs readEntriesAtURL:localURI];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -615,7 +643,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSInteger start = [[command argumentAtIndex:2] integerValue];
NSInteger end = [[command argumentAtIndex:3] integerValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
// TODO: implement
if ([@"UTF-8" caseInsensitiveCompare : encoding] != NSOrderedSame) {
@@ -663,7 +691,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSInteger start = [[command argumentAtIndex:1] integerValue];
NSInteger end = [[command argumentAtIndex:2] integerValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[self.commandDelegate runInBackground:^ {
[fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString* mimeType, CDVFileError errorCode) {
@@ -695,7 +723,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSInteger start = [[command argumentAtIndex:1] integerValue];
NSInteger end = [[command argumentAtIndex:2] integerValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[self.commandDelegate runInBackground:^ {
[fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString* mimeType, CDVFileError errorCode) {
@@ -717,7 +745,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
NSInteger start = [[command argumentAtIndex:1] integerValue];
NSInteger end = [[command argumentAtIndex:2] integerValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[self.commandDelegate runInBackground:^ {
[fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString* mimeType, CDVFileError errorCode) {
@@ -742,7 +770,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command argumentAtIndex:0]];
unsigned long long pos = (unsigned long long)[[command.arguments objectAtIndex:1] longLongValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
CDVPluginResult *result = [fs truncateFileAtURL:localURI atPosition:pos];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -766,7 +794,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
id argData = [arguments objectAtIndex:1];
unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+ NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
[fs truncateFileAtURL:localURI atPosition:pos];
@@ -841,7 +869,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
- (NSDictionary *)getDirectoryEntry:(NSString *)localPath isDirectory:(BOOL)bDirRequest
{
CDVFilesystemURL *localURL = [self fileSystemURLforLocalPath:localPath];
- return [self makeEntryForPath:localURL.fullPath fileSystem:localURL.fileSystemType isDirectory:bDirRequest];
+ return [self makeEntryForPath:localURL.fullPath fileSystemName:localURL.fileSystemName isDirectory:bDirRequest];
}
#pragma mark Internal methods for testing
@@ -849,9 +877,12 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
// [Currently used for testing file-transfer]
- (NSString *)_filesystemPathForURL:(CDVFilesystemURL *)localURL
{
- CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURL.fileSystemType];
- if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
- return [fs filesystemPathForURL:localURL];
+ for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
+ if ([fs.name isEqualToString:localURL.fileSystemName]) {
+ if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
+ return [fs filesystemPathForURL:localURL];
+ }
+ }
}
return nil;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVLocalFilesystem.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.h b/src/ios/CDVLocalFilesystem.h
index 65c9269..a0186c8 100644
--- a/src/ios/CDVLocalFilesystem.h
+++ b/src/ios/CDVLocalFilesystem.h
@@ -27,7 +27,6 @@
- (id) initWithName:(NSString *)name root:(NSString *)fsRoot;
+ (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
-@property (nonatomic,strong) NSString *name;
@property (nonatomic,strong) NSString *fsRoot;
@end
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 5ad2200..3e054c8 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -61,12 +61,12 @@
// see if exists and is file or dir
BOOL bExists = [fileMgr fileExistsAtPath:path isDirectory:&isDir];
if (bExists) {
- return [self makeEntryForPath:url.fullPath fileSystem:url.fileSystemType isDirectory:isDir];
+ return [self makeEntryForPath:url.fullPath fileSystemName:url.fileSystemName isDirectory:isDir];
} else {
return nil;
}
}
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
{
NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
NSString* lastPart = [fullPath lastPathComponent];
@@ -77,7 +77,8 @@
[dirEntry setObject:[NSNumber numberWithBool:isDir] forKey:@"isDirectory"];
[dirEntry setObject:fullPath forKey:@"fullPath"];
[dirEntry setObject:lastPart forKey:@"name"];
- [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
+ [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ? 0 : 1)] forKey: @"filesystem"];
+ [dirEntry setObject:fsName forKey: @"filesystemName"];
return dirEntry;
}
@@ -173,7 +174,7 @@
} else {
// NSLog(@"newly created file/dir (%@) exists: %d", reqFullPath, [fileMgr fileExistsAtPath:reqFullPath]);
// file existed or was created
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self makeEntryForPath:requestedURL.fullPath fileSystem:baseURI.fileSystemType isDirectory:bDirRequest]];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self makeEntryForPath:requestedURL.fullPath fileSystemName:baseURI.fileSystemName isDirectory:bDirRequest]];
}
} // are all possible conditions met?
}
@@ -200,7 +201,7 @@
BOOL bIsDir;
BOOL bExists = [fileMgr fileExistsAtPath:[self filesystemPathForURL:newURI] isDirectory:&bIsDir];
if (bExists) {
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self makeEntryForPath:newURI.fullPath fileSystem:newURI.fileSystemType isDirectory:bIsDir]];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self makeEntryForPath:newURI.fullPath fileSystemName:newURI.fileSystemName isDirectory:bIsDir]];
} else {
// invalid path or file does not exist
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
@@ -367,7 +368,7 @@
NSString* entryPath = [fileSystemPath stringByAppendingPathComponent:name];
BOOL bIsDir = NO;
[fileMgr fileExistsAtPath:entryPath isDirectory:&bIsDir];
- NSDictionary* entryDict = [self makeEntryForPath:[self fullPathForFileSystemPath:entryPath] fileSystem:localURI.fileSystemType isDirectory:bIsDir];
+ NSDictionary* entryDict = [self makeEntryForPath:[self fullPathForFileSystemPath:entryPath] fileSystemName:localURI.fileSystemName isDirectory:bIsDir];
[entries addObject:entryDict];
}
}
@@ -549,7 +550,7 @@
}
if (bSuccess) {
// should verify it is there and of the correct type???
- NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystem:srcURL.fileSystemType isDirectory:bSrcIsDir]; // should be the same type as source
+ NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystemName:srcURL.fileSystemName isDirectory:bSrcIsDir]; // should be the same type as source
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newEntry];
} else {
if (error) {
@@ -571,7 +572,7 @@
BOOL bSuccess = [data writeToFile:newFileSystemPath atomically:YES];
if (bSuccess) {
// should verify it is there and of the correct type???
- NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystem:destURL.fileSystemType isDirectory:NO];
+ NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystemName:destURL.fileSystemName isDirectory:NO];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newEntry];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:ABORT_ERR];
[41/50] git commit: Fill out filesystem attribute of entities
returned from resolveLocalFileSystemURL
Posted by st...@apache.org.
Fill out filesystem attribute of entities returned from resolveLocalFileSystemURL
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/2bfa0759
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/2bfa0759
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/2bfa0759
Branch: refs/heads/master
Commit: 2bfa0759701f64b09a6484feb13a71c551f9d39a
Parents: 620bb7c
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Jan 28 14:35:33 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Jan 28 14:35:33 2014 -0500
----------------------------------------------------------------------
www/resolveLocalFileSystemURI.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2bfa0759/www/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/resolveLocalFileSystemURI.js b/www/resolveLocalFileSystemURI.js
index 6fef4b1..8c97d31 100644
--- a/www/resolveLocalFileSystemURI.js
+++ b/www/resolveLocalFileSystemURI.js
@@ -50,7 +50,7 @@ module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorC
if (successCallback) {
// create appropriate Entry object
var fsName = entry.filesystemName || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
- var fs = new FileSystem(fsName);
+ var fs = new FileSystem(fsName, {name:"", fullPath:"/"});
var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs) : new FileEntry(entry.name, entry.fullPath, fs);
successCallback(result);
}
[15/50] git commit: CB-4899 [BlackBerry10] Fix resolve directories
Posted by st...@apache.org.
CB-4899 [BlackBerry10] Fix resolve directories
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/e7f83cb7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/e7f83cb7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/e7f83cb7
Branch: refs/heads/master
Commit: e7f83cb7de0f989ed95de57fdf38255fcdc9b86f
Parents: 51be28e
Author: Bryan Higgins <bh...@blackberry.com>
Authored: Thu Jan 9 11:26:14 2014 -0500
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Thu Jan 9 11:28:20 2014 -0500
----------------------------------------------------------------------
www/blackberry10/resolveLocalFileSystemURI.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e7f83cb7/www/blackberry10/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/resolveLocalFileSystemURI.js b/www/blackberry10/resolveLocalFileSystemURI.js
index f447a42..fd0e217 100644
--- a/www/blackberry10/resolveLocalFileSystemURI.js
+++ b/www/blackberry10/resolveLocalFileSystemURI.js
@@ -31,10 +31,10 @@ module.exports = function (uri, success, fail) {
resolveURI = function () {
window.webkitRequestFileSystem(
window.PERSISTENT,
- //todo: match app quota (this is only used for sandboxed fs)
50*1024*1024,
function (fs) {
- fs.root.getFile(
+ var op = decodedURI.slice(-1) === '/' ? 'getDirectory' : 'getFile';
+ fs.root[op](
decodedURI,
{ create: false },
function (entry) {
[02/50] git commit: Merge branch "android-file" into dev
Posted by st...@apache.org.
Merge branch "android-file" into dev
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/0a6adf02
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/0a6adf02
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/0a6adf02
Branch: refs/heads/master
Commit: 0a6adf0221920c1eb3e3635f2ba5dcfd41836f3b
Parents: 7872b9c 2550617
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Dec 13 11:15:56 2013 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Fri Dec 13 11:15:56 2013 -0500
----------------------------------------------------------------------
plugin.xml | 10 +
src/android/ContentFilesystem.java | 111 ++++
src/android/FileUtils.java | 900 +++++++++----------------------
src/android/Filesystem.java | 40 ++
src/android/LocalFilesystem.java | 617 +++++++++++++++++++++
src/android/LocalFilesystemURL.java | 54 ++
src/android/ReadFileCallback.java | 5 +
www/Entry.js | 5 +-
www/android/FileSystem.js | 27 +
9 files changed, 1113 insertions(+), 656 deletions(-)
----------------------------------------------------------------------
[18/50] git commit: Initial fix for CB-5747
Posted by st...@apache.org.
Initial fix for CB-5747
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/3e4f9cdc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/3e4f9cdc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/3e4f9cdc
Branch: refs/heads/master
Commit: 3e4f9cdc287d907679a47a32f95238180c774860
Parents: cfdb4ed
Author: Matti Eerola <ma...@softapalvelin.com>
Authored: Sat Jan 11 12:37:01 2014 +0000
Committer: Matti Eerola <ma...@softapalvelin.com>
Committed: Sat Jan 11 12:37:01 2014 +0000
----------------------------------------------------------------------
src/windows8/FileProxy.js | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/3e4f9cdc/src/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/FileProxy.js b/src/windows8/FileProxy.js
index 1445ae7..4a20c64 100644
--- a/src/windows8/FileProxy.js
+++ b/src/windows8/FileProxy.js
@@ -194,6 +194,10 @@ module.exports = {
flag = new Flags(false, false);
}
+ if (path !== null) {
+ path = path.replace("/", "\\");
+ }
+
Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(
function (storageFolder) {
if (flag.create === true && flag.exclusive === true) {
[14/50] git commit: Merge branch 'CB-5602' of
https://github.com/sgrebnov/cordova-plugin-file into dev
Posted by st...@apache.org.
Merge branch 'CB-5602' of https://github.com/sgrebnov/cordova-plugin-file into dev
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/51be28ee
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/51be28ee
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/51be28ee
Branch: refs/heads/master
Commit: 51be28eeb87dfab80624601880ae6a9b8f3dcf06
Parents: 68b29cc 2de4d8d
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Jan 7 17:26:15 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Jan 7 17:26:15 2014 -0800
----------------------------------------------------------------------
src/windows8/FileProxy.js | 164 ++++++++++++++++++++-------------
test/autotest/tests/file.tests.js | 8 +-
2 files changed, 105 insertions(+), 67 deletions(-)
----------------------------------------------------------------------