in src/browser/FileProxy.js [351:426]
exports.getDirectory = function (successCallback, errorCallback, args) {
const fullPath = args[0];
let path = args[1];
let options = args[2];
// Create an absolute path if we were handed a relative one.
path = resolveToFullPath_(fullPath, path);
idb_.get(path.storagePath, function (folderEntry) {
if (!options) {
options = {};
}
if (options.create === true && options.exclusive === true && folderEntry) {
// If create and exclusive are both true, and the path already exists,
// getDirectory must fail.
if (errorCallback) {
errorCallback(FileError.PATH_EXISTS_ERR);
}
// There is a strange bug in mobilespec + FF, which results in coming to multiple else-if's
// so we are shielding from it with returns.
return;
}
if (options.create === true && !folderEntry) {
// If create is true, the path doesn't exist, and no other error occurs,
// getDirectory must create it as a zero-length file and return a corresponding
// MyDirectoryEntry.
const dirEntry = new DirectoryEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
idb_.put(dirEntry, path.storagePath, successCallback, errorCallback);
return;
}
if (options.create === true && folderEntry) {
if (folderEntry.isDirectory) {
// IDB won't save methods, so we need re-create the MyDirectoryEntry.
successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem));
} else {
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
}
return;
}
if ((!options.create || options.create === false) && !folderEntry) {
// Handle root special. It should always exist.
if (path.fullPath === DIR_SEPARATOR) {
successCallback(fs_.root);
return;
}
// If create is not true and the path doesn't exist, getDirectory must fail.
if (errorCallback) {
errorCallback(FileError.NOT_FOUND_ERR);
}
return;
}
if ((!options.create || options.create === false) && folderEntry && folderEntry.isFile) {
// If create is not true and the path exists, but is a file, getDirectory
// must fail.
if (errorCallback) {
errorCallback(FileError.TYPE_MISMATCH_ERR);
}
return;
}
// Otherwise, if no other error occurs, getDirectory must return a
// MyDirectoryEntry corresponding to path.
// IDB won't' save methods, so we need re-create MyDirectoryEntry.
successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem));
}, errorCallback);
};