timbru31 commented on a change in pull request #405:
URL:
https://github.com/apache/cordova-plugin-file/pull/405#discussion_r448952928
##########
File path: src/browser/FileProxy.js
##########
@@ -141,103 +147,121 @@
// 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.
+ 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.
- var 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 () {
- var 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);
+ errorCallback(FileError.PATH_EXISTS_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.
+ } 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.
+ var 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 () {
+ var 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);
+ successCallback(fileEntryFromIdbEntry(fileEntry));
+ }
+ },
+ errorCallback
+ );
};
exports.getFileMetadata = function (successCallback, errorCallback,
args) {
var fullPath = args[0];
- exports.getFile(function (fileEntry) {
- successCallback(new File(fileEntry.file_.name,
fileEntry.fullPath, '', fileEntry.file_.lastModifiedDate,
- fileEntry.file_.size));
- }, errorCallback, [fullPath, null]);
+ exports.getFile(
+ function (fileEntry) {
+ successCallback(
+ new File(fileEntry.file_.name, fileEntry.fullPath, '',
fileEntry.file_.lastModifiedDate, fileEntry.file_.size)
+ );
+ },
+ errorCallback,
+ [fullPath, null]
+ );
};
exports.getMetadata = function (successCallback, errorCallback, args) {
- exports.getFile(function (fileEntry) {
- successCallback(
- {
+ exports.getFile(
+ function (fileEntry) {
+ successCallback({
modificationTime: fileEntry.file_.lastModifiedDate,
size: fileEntry.file_.lastModifiedDate
});
- }, errorCallback, args);
+ },
+ errorCallback,
+ args
+ );
};
exports.setMetadata = function (successCallback, errorCallback, args) {
var fullPath = args[0];
var metadataObject = args[1];
- exports.getFile(function (fileEntry) {
- fileEntry.file_.lastModifiedDate =
metadataObject.modificationTime;
- idb_.put(fileEntry, fileEntry.file_.storagePath,
successCallback, errorCallback);
- }, errorCallback, [fullPath, null]);
+ exports.getFile(
+ function (fileEntry) {
+ fileEntry.file_.lastModifiedDate =
metadataObject.modificationTime;
+ idb_.put(fileEntry, fileEntry.file_.storagePath,
successCallback, errorCallback);
+ },
+ errorCallback,
+ [fullPath, null]
+ );
};
exports.write = function (successCallback, errorCallback, args) {
var fileName = args[0];
var data = args[1];
var position = args[2];
- var isBinary = args[3]; // eslint-disable-line no-unused-vars
Review comment:
No reason to allocate memory if the variable is not used.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]