Skip to content

Instantly share code, notes, and snippets.

@kenmanheimer
Created September 3, 2014 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenmanheimer/72510607541f34792046 to your computer and use it in GitHub Desktop.
Save kenmanheimer/72510607541f34792046 to your computer and use it in GitHub Desktop.
/** Show cordova .getFile() problem with some filenames containing "%" char.
*
* We create a file with the specified name in the Download dir,
* indicating whether or not the name of the created file is the same as
* that specified. On Android, the name is different if the specified
* one contains a sequence of chars starting with a "%" and not
* qualifying as a proper character entity - because of
* https://github.com/apache/cordova-plugin-file/blob/master/www/android/FileSystem.js#L29
*
* @param(string) filename - defaults to "x%y", which shows the problem.
*/
window.charEntityDemo = function(filename) {
var demoDir = "Download",
demoFilename = filename || "x%y";
function getFSThenFile() {
window.requestFileSystem(
window.LocalFileSystem.PERSISTENT, 0,
function (fileSystem) {
fileSystem.root.getDirectory(
demoDir,
{create: false, exclusive: true},
getFileThenRemove,
function (ferr) {
console.log("Get dir " + demoDir + " failed: " + ferr.code);
});
},
function (evt) {
console.log("Root filesystem request failed - " +
evt.target.error.code);
});
}
function getFileThenRemove(dirEntry) {
dirEntry.getFile(
demoFilename,
{create: true, exclusive: false},
function (fileEntry) {
/*** Report whether or not the file is named as specified: ***/
if (fileEntry.name !== demoFilename) {
console.log("Got file specified as: " + demoFilename +
", but file entry named: " + fileEntry.name);
} else {
console.log("Got file, named as specified: " + fileEntry.name);
}
// ... and remove the file, whatever it is named.
fileEntry.remove(
function () {
console.log("(" + fileEntry.name+ " removed)");
},
function (ferr) {
console.log("File removal failed: " + fileEntry.name +
", error code: " + ferr.code);
});
},
function (ferr) {
console.log("Failed to get: " + dirEntry.fullPath + demoFilename +
", FileError code " + ferr.code);
});
}
getFSThenFile();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment