diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js old mode 100755 new mode 100644 index b090ac40..a3864737 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -2216,7 +2216,7 @@ var utils = require('cordova/utils'), /** * An interface representing a directory on the file system. - * + * * {boolean} isFile always false (readonly) * {boolean} isDirectory always true (readonly) * {DOMString} name of the directory, excluding the path leading to it (readonly) @@ -2245,11 +2245,11 @@ DirectoryEntry.prototype.createReader = function() { * @param {Function} errorCallback is called with a FileError */ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) { - var win = function(result) { + var win = typeof successCallback !== 'function' ? null : function(result) { var entry = new DirectoryEntry(result.name, result.fullPath); successCallback(entry); }; - var fail = function(code) { + var fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(new FileError(code)); }; exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]); @@ -2262,7 +2262,7 @@ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, * @param {Function} errorCallback is called with a FileError */ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) { - var fail = function(code) { + var fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(new FileError(code)); }; exec(successCallback, fail, "File", "removeRecursively", [this.fullPath]); @@ -2277,12 +2277,12 @@ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCall * @param {Function} errorCallback is called with a FileError */ DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) { - var win = function(result) { + var win = typeof successCallback !== 'function' ? null : function(result) { var FileEntry = require('cordova/plugin/FileEntry'); var entry = new FileEntry(result.name, result.fullPath); successCallback(entry); }; - var fail = function(code) { + var fail = typeof errorCallback !== 'function' ? null : function(code) { errorCallback(new FileError(code)); }; exec(win, fail, "File", "getFile", [this.fullPath, path, options]); @@ -2309,7 +2309,7 @@ function DirectoryReader(path) { * @param {Function} errorCallback is called with a FileError */ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { - var win = function(result) { + var win = typeof successCallback !== 'function' ? null : function(result) { var retVal = []; for (var i=0; i 3) { - if (typeof errorCallback === "function") { - errorCallback(new FileError(FileError.SYNTAX_ERR)); - } - } else { - // if successful, return a FileSystem object - var success = function(file_system) { - if (file_system) { - // grab the name and root from the file system object - var result = new FileSystem(file_system.name, file_system.root); - successCallback(result); - } - else { - // no FileSystem object returned - errorCallback(new FileError(FileError.NOT_FOUND_ERR)); - } + var fail = function(code) { + if (typeof errorCallback === 'function') { + errorCallback(new FileError(code)); + } }; - var fail = function(e) { - errorCallback(new FileError(e)); - }; - exec(success, fail, "File", "requestFileSystem", [type, size]); - } + + if (type < 0 || type > 3) { + fail(FileError.SYNTAX_ERR); + } else { + // if successful, return a FileSystem object + var success = function(file_system) { + if (file_system) { + if (typeof successCallback === 'function') { + // grab the name and root from the file system object + var result = new FileSystem(file_system.name, file_system.root); + successCallback(result); + } + } + else { + // no FileSystem object returned + fail(FileError.NOT_FOUND_ERR); + } + }; + exec(success, fail, "File", "requestFileSystem", [type, size]); + } }; module.exports = requestFileSystem; @@ -3983,27 +3987,31 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry'), /** * Look up file system Entry referred to by local URI. - * @param {DOMString} uri URI referring to a local file or directory + * @param {DOMString} uri URI referring to a local file or directory * @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) { // error callback var fail = function(error) { - errorCallback(new FileError(error)); + if (typeof errorCallback === 'function') { + errorCallback(new FileError(error)); + } }; // if successful, return either a file or directory entry var success = function(entry) { var result; if (entry) { - // create appropriate Entry object - result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath); - try { - successCallback(result); - } - catch (e) { - console.log('Error invoking callback: ' + e); + if (typeof successCallback === 'function') { + // create appropriate Entry object + result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath); + try { + successCallback(result); + } + catch (e) { + console.log('Error invoking callback: ' + e); + } } } else { diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 7dc26f32..297219de 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -815,27 +815,31 @@ public class FileUtils extends Plugin { File fp; fs.put("name", "temporary"); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - fs.put("root", "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + - "/Android/data/" + ctx.getPackageName() + "/cache/"); - - // Create the cache dir if it doesn't exist. fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + ctx.getPackageName() + "/cache/"); - } else { - fs.put("root", "file:///data/data/" + ctx.getPackageName() + "/cache/"); // Create the cache dir if it doesn't exist. + fp.mkdirs(); + fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() + + "/Android/data/" + ctx.getPackageName() + "/cache/")); + } else { fp = new File("/data/data/" + ctx.getPackageName() + "/cache/"); + // Create the cache dir if it doesn't exist. + fp.mkdirs(); + fs.put("root", getEntry("/data/data/" + ctx.getPackageName() + "/cache/")); } - fp.mkdirs(); } else if (type == PERSISTENT) { fs.put("name", "persistent"); - fs.put("root", "file:///data/data/" + ctx.getPackageName()); + if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + fs.put("root", getEntry(Environment.getExternalStorageDirectory())); + } else { + fs.put("root", getEntry("/data/data/" + ctx.getPackageName())); + } } else { throw new IOException("No filesystem of type requested"); } - + return fs; }