in src/browser/FileProxy.js [136:205]
exports.getFile = function (successCallback, errorCallback, args) {
const fullPath = args[0];
let path = args[1];
const options = args[2] || {};
// Create an absolute path if we were handed a relative one.
path = resolveToFullPath_(fullPath, path);
idb_.get(path.storagePath, function (fileEntry) {
if (options.create === true && options.exclusive === true && fileEntry) {
// If create and exclusive are both true, and the path already exists,
// getFile must fail.
if (errorCallback) {
errorCallback(FileError.PATH_EXISTS_ERR);
}
} else if (options.create === true && !fileEntry) {
// If create is true, the path doesn't exist, and no other error occurs,
// getFile must create it as a zero-length file and return a corresponding
// FileEntry.
const newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
newFileEntry.file_ = new MyFile({
size: 0,
name: newFileEntry.name,
lastModifiedDate: new Date(),
storagePath: path.storagePath
});
idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback);
} else if (options.create === true && fileEntry) {
if (fileEntry.isFile) {
// Overwrite file, delete then create new.
idb_.delete(path.storagePath, function () {
const newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root));
newFileEntry.file_ = new MyFile({
size: 0,
name: newFileEntry.name,
lastModifiedDate: new Date(),
storagePath: path.storagePath
});
idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback);
}, errorCallback);
} else {
if (errorCallback) {
errorCallback(FileError.INVALID_MODIFICATION_ERR);
}
}
} else if ((!options.create || options.create === false) && !fileEntry) {
// If create is not true and the path doesn't exist, getFile must fail.
if (errorCallback) {
errorCallback(FileError.NOT_FOUND_ERR);
}
} else if ((!options.create || options.create === false) && fileEntry &&
fileEntry.isDirectory) {
// If create is not true and the path exists, but is a directory, getFile
// must fail.
if (errorCallback) {
errorCallback(FileError.TYPE_MISMATCH_ERR);
}
} else {
// Otherwise, if no other error occurs, getFile must return a FileEntry
// corresponding to path.
successCallback(fileEntryFromIdbEntry(fileEntry));
}
}, errorCallback);
};