forked from github/cordova-android
Revert change in location of FileSystem
This commit is contained in:
parent
79935d31ef
commit
21b7346277
164
framework/assets/js/cordova.android.js
Executable file → Normal file
164
framework/assets/js/cordova.android.js
Executable file → Normal file
@ -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<result.length; i++) {
|
||||
var entry = null;
|
||||
@ -2327,7 +2327,7 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback)
|
||||
}
|
||||
successCallback(retVal);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "readEntries", [this.path]);
|
||||
@ -2373,13 +2373,14 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
|
||||
* {Function} is called with a FileError
|
||||
*/
|
||||
Entry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
var success = function(lastModified) {
|
||||
var success = typeof successCallback !== 'function' ? null : function(lastModified) {
|
||||
var metadata = new Metadata(lastModified);
|
||||
successCallback(metadata);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
exec(success, fail, "File", "getMetadata", [this.fullPath]);
|
||||
};
|
||||
|
||||
@ -2396,40 +2397,39 @@ Entry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
// user must specify parent Entry
|
||||
if (!parent) {
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
return;
|
||||
}
|
||||
// source path
|
||||
var srcPath = this.fullPath,
|
||||
// entry name
|
||||
name = newName || this.name,
|
||||
// destination path
|
||||
dstPath,
|
||||
success = function(entry) {
|
||||
var result;
|
||||
|
||||
if (entry) {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
if (typeof successCallback === 'function') {
|
||||
// create appropriate Entry object
|
||||
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
},
|
||||
fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
|
||||
// copy
|
||||
exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]);
|
||||
};
|
||||
@ -2447,9 +2447,15 @@ Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallbac
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
|
||||
// user must specify parent Entry
|
||||
if (!parent) {
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2459,25 +2465,22 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac
|
||||
name = newName || this.name,
|
||||
// success callback
|
||||
success = function(entry) {
|
||||
var result;
|
||||
|
||||
if (entry) {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
if (typeof successCallback === 'function') {
|
||||
// create appropriate Entry object
|
||||
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
},
|
||||
fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
// copy
|
||||
@ -2513,8 +2516,8 @@ Entry.prototype.toURI = function(mimeType) {
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.remove = function(successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "remove", [this.fullPath]);
|
||||
};
|
||||
@ -2526,7 +2529,7 @@ Entry.prototype.remove = function(successCallback, errorCallback) {
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "getParent", [this.fullPath]);
|
||||
@ -2610,12 +2613,12 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
||||
var win = function(f) {
|
||||
var win = typeof successCallback !== 'function' ? null : function(f) {
|
||||
var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
|
||||
successCallback(file);
|
||||
};
|
||||
var fail = function(e) {
|
||||
errorCallback(new FileError(e));
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
|
||||
};
|
||||
@ -2857,7 +2860,6 @@ FileReader.prototype.readAsDataURL = function(file) {
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
var evt;
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileReader.DONE) {
|
||||
return;
|
||||
@ -2920,7 +2922,7 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
|
||||
var FileSystem = function(name, root) {
|
||||
this.name = name || null;
|
||||
if (root) {
|
||||
this.root = new DirectoryEntry(name, root);
|
||||
this.root = new DirectoryEntry(root.name, root.fullPath);
|
||||
}
|
||||
};
|
||||
|
||||
@ -3149,7 +3151,6 @@ FileWriter.prototype.write = function(text) {
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
@ -3948,28 +3949,31 @@ var FileError = require('cordova/plugin/FileError'),
|
||||
* @param errorCallback invoked if error occurs retrieving file system
|
||||
*/
|
||||
var requestFileSystem = function(type, size, successCallback, errorCallback) {
|
||||
if (type < 0 || type > 3) {
|
||||
if (typeof errorCallback === "function") {
|
||||
errorCallback(new FileError(FileError.SYNTAX_ERR));
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
|
||||
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]);
|
||||
}
|
||||
} 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(e) {
|
||||
errorCallback(new FileError(e));
|
||||
};
|
||||
exec(success, fail, "File", "requestFileSystem", [type, size]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = requestFileSystem;
|
||||
@ -3990,20 +3994,24 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
|
||||
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 {
|
||||
|
@ -815,22 +815,26 @@ 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");
|
||||
|
Loading…
Reference in New Issue
Block a user