Fix typos and clean up for review

This commit is contained in:
David Humphrey 2018-06-25 08:26:59 -04:00
parent 46698f30e2
commit b7ecae4af1
3 changed files with 28 additions and 30 deletions

View File

@ -48,17 +48,17 @@ var Buffer = require('../buffer.js');
* and filesystem flags are examined in order to override update logic. * and filesystem flags are examined in order to override update logic.
*/ */
function update_node_times(context, path, node, times, callback) { function update_node_times(context, path, node, times, callback) {
var update = false;
// Honour mount flags for how we update times // Honour mount flags for how we update times
var flags = context.flags; var flags = context.flags;
if(_(flags).contains(FS_NOCTIME)) { if(_(flags).contains(FS_NOCTIME)) {
delete times.ctime; delete times.ctime;
} }
if(_(flags).contains(FS_NOMTIME)) { if(_(flags).contains(FS_NOMTIME)) {
delete times.mtime; delete times.mtime;
} }
// Only do the update if required (i.e., times are still present)
var update = false;
if(times.ctime) { if(times.ctime) {
node.ctime = times.ctime; node.ctime = times.ctime;
// We don't do atime tracking for perf reasons, but do mirror ctime // We don't do atime tracking for perf reasons, but do mirror ctime
@ -239,7 +239,7 @@ function find_node(context, path, callback) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
if(node.type == NODE_TYPE_SYMBOLIC_LINK) { if(node.type === NODE_TYPE_SYMBOLIC_LINK) {
followedCount++; followedCount++;
if(followedCount > SYMLOOP_MAX){ if(followedCount > SYMLOOP_MAX){
callback(new Errors.ELOOP(null, path)); callback(new Errors.ELOOP(null, path));
@ -256,14 +256,14 @@ function find_node(context, path, callback) {
data = normalize(data); data = normalize(data);
parentPath = dirname(data); parentPath = dirname(data);
name = basename(data); name = basename(data);
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
context.getObject(SUPER_NODE_ID, read_root_directory_node); context.getObject(SUPER_NODE_ID, read_root_directory_node);
} else { } else {
find_node(context, parentPath, read_parent_directory_data); find_node(context, parentPath, read_parent_directory_data);
} }
} }
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
context.getObject(SUPER_NODE_ID, read_root_directory_node); context.getObject(SUPER_NODE_ID, read_root_directory_node);
} else { } else {
find_node(context, parentPath, read_parent_directory_data); find_node(context, parentPath, read_parent_directory_data);
@ -316,7 +316,7 @@ function ensure_root_directory(context, callback) {
} else if(error && !(error instanceof Errors.ENOENT)) { } else if(error && !(error instanceof Errors.ENOENT)) {
callback(error); callback(error);
} else { } else {
SuperNode.create({ guid: context.guid }, function(error, result) { SuperNode.create({guid: context.guid}, function(error, result) {
if(error) { if(error) {
callback(error); callback(error);
return; return;
@ -466,7 +466,7 @@ function remove_directory(context, path, callback) {
function check_if_node_exists(error, result) { function check_if_node_exists(error, result) {
if(error) { if(error) {
callback(error); callback(error);
} else if(ROOT_DIRECTORY_NAME == name) { } else if(ROOT_DIRECTORY_NAME === name) {
callback(new Errors.EBUSY(null, path)); callback(new Errors.EBUSY(null, path));
} else if(!_(result).has(name)) { } else if(!_(result).has(name)) {
callback(new Errors.ENOENT(null, path)); callback(new Errors.ENOENT(null, path));
@ -480,7 +480,7 @@ function remove_directory(context, path, callback) {
function check_if_node_is_directory(error, result) { function check_if_node_is_directory(error, result) {
if(error) { if(error) {
callback(error); callback(error);
} else if(result.type != NODE_TYPE_DIRECTORY) { } else if(result.type !== NODE_TYPE_DIRECTORY) {
callback(new Errors.ENOTDIR(null, path)); callback(new Errors.ENOTDIR(null, path));
} else { } else {
directoryNode = result; directoryNode = result;
@ -547,7 +547,7 @@ function open_file(context, path, flags, callback) {
var followedCount = 0; var followedCount = 0;
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
if(_(flags).contains(O_WRITE)) { if(_(flags).contains(O_WRITE)) {
callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path));
} else { } else {
@ -578,7 +578,7 @@ function open_file(context, path, flags, callback) {
callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path)); callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path));
} else { } else {
directoryEntry = directoryData[name]; directoryEntry = directoryData[name];
if(directoryEntry.type == NODE_TYPE_DIRECTORY && _(flags).contains(O_WRITE)) { if(directoryEntry.type === NODE_TYPE_DIRECTORY && _(flags).contains(O_WRITE)) {
callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path));
} else { } else {
context.getObject(directoryEntry.id, check_if_symbolic_link); context.getObject(directoryEntry.id, check_if_symbolic_link);
@ -599,7 +599,7 @@ function open_file(context, path, flags, callback) {
callback(error); callback(error);
} else { } else {
var node = result; var node = result;
if(node.type == NODE_TYPE_SYMBOLIC_LINK) { if(node.type === NODE_TYPE_SYMBOLIC_LINK) {
followedCount++; followedCount++;
if(followedCount > SYMLOOP_MAX){ if(followedCount > SYMLOOP_MAX){
callback(new Errors.ELOOP(null, path)); callback(new Errors.ELOOP(null, path));
@ -616,7 +616,7 @@ function open_file(context, path, flags, callback) {
data = normalize(data); data = normalize(data);
parentPath = dirname(data); parentPath = dirname(data);
name = basename(data); name = basename(data);
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
if(_(flags).contains(O_WRITE)) { if(_(flags).contains(O_WRITE)) {
callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path)); callback(new Errors.EISDIR('the named file is a directory and O_WRITE is set', path));
} else { } else {
@ -857,7 +857,7 @@ function lstat_file(context, path, callback) {
var directoryNode; var directoryNode;
var directoryData; var directoryData;
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
find_node(context, path, callback); find_node(context, path, callback);
} else { } else {
find_node(context, parentPath, read_directory_data); find_node(context, parentPath, read_directory_data);
@ -1100,7 +1100,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) {
var directoryData; var directoryData;
var fileNode; var fileNode;
if(ROOT_DIRECTORY_NAME == name) { if(ROOT_DIRECTORY_NAME === name) {
callback(new Errors.EEXIST(null, name)); callback(new Errors.EEXIST(null, name));
} else { } else {
find_node(context, parentPath, read_directory_data); find_node(context, parentPath, read_directory_data);
@ -1209,7 +1209,7 @@ function read_link(context, path, callback) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
if(fileNode.type != NODE_TYPE_SYMBOLIC_LINK) { if(fileNode.type !== NODE_TYPE_SYMBOLIC_LINK) {
callback(new Errors.EINVAL('path not a symbolic link', path)); callback(new Errors.EINVAL('path not a symbolic link', path));
} else { } else {
// If we were originally given a relative path, return that now vs. the // If we were originally given a relative path, return that now vs. the
@ -1229,7 +1229,7 @@ function truncate_file(context, path, length, callback) {
function read_file_data (error, node) { function read_file_data (error, node) {
if (error) { if (error) {
callback(error); callback(error);
} else if(node.type == NODE_TYPE_DIRECTORY ) { } else if(node.type === NODE_TYPE_DIRECTORY ) {
callback(new Errors.EISDIR(null, path)); callback(new Errors.EISDIR(null, path));
} else{ } else{
fileNode = node; fileNode = node;
@ -1285,7 +1285,7 @@ function ftruncate_file(context, ofd, length, callback) {
function read_file_data (error, node) { function read_file_data (error, node) {
if (error) { if (error) {
callback(error); callback(error);
} else if(node.type == NODE_TYPE_DIRECTORY ) { } else if(node.type === NODE_TYPE_DIRECTORY ) {
callback(new Errors.EISDIR()); callback(new Errors.EISDIR());
} else{ } else{
fileNode = node; fileNode = node;
@ -1348,7 +1348,7 @@ function utimes_file(context, path, atime, mtime, callback) {
} }
} }
if (typeof atime != 'number' || typeof mtime != 'number') { if (typeof atime !== 'number' || typeof mtime !== 'number') {
callback(new Errors.EINVAL('atime and mtime must be number', path)); callback(new Errors.EINVAL('atime and mtime must be number', path));
} }
else if (atime < 0 || mtime < 0) { else if (atime < 0 || mtime < 0) {
@ -1369,7 +1369,7 @@ function futimes_file(context, ofd, atime, mtime, callback) {
} }
} }
if (typeof atime != 'number' || typeof mtime != 'number') { if (typeof atime !== 'number' || typeof mtime !== 'number') {
callback(new Errors.EINVAL('atime and mtime must be a number')); callback(new Errors.EINVAL('atime and mtime must be a number'));
} }
else if (atime < 0 || mtime < 0) { else if (atime < 0 || mtime < 0) {
@ -1390,7 +1390,7 @@ function setxattr_file(context, path, name, value, flag, callback) {
set_extended_attribute(context, path, node, name, value, flag, callback); set_extended_attribute(context, path, node, name, value, flag, callback);
} }
if (typeof name != 'string') { if (typeof name !== 'string') {
callback(new Errors.EINVAL('attribute name must be a string', path)); callback(new Errors.EINVAL('attribute name must be a string', path));
} }
else if (!name) { else if (!name) {
@ -1446,7 +1446,7 @@ function getxattr_file (context, path, name, callback) {
} }
} }
if (typeof name != 'string') { if (typeof name !== 'string') {
callback(new Errors.EINVAL('attribute name must be a string', path)); callback(new Errors.EINVAL('attribute name must be a string', path));
} }
else if (!name) { else if (!name) {
@ -1474,7 +1474,7 @@ function fgetxattr_file (context, ofd, name, callback) {
} }
} }
if (typeof name != 'string') { if (typeof name !== 'string') {
callback(new Errors.EINVAL()); callback(new Errors.EINVAL());
} }
else if (!name) { else if (!name) {
@ -1549,7 +1549,7 @@ function fremovexattr_file (context, ofd, name, callback) {
} }
} }
if (typeof name != 'string') { if (typeof name !== 'string') {
callback(new Errors.EINVAL('attribute name must be a string')); callback(new Errors.EINVAL('attribute name must be a string'));
} }
else if (!name) { else if (!name) {
@ -1937,7 +1937,7 @@ function validateAndMaskMode(value, def, callback) {
return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS; return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS;
} }
// TODO(BridgeAR): Only return `def` in case `value == null` // TODO(BridgeAR): Only return `def` in case `value === null`
if (def !== undefined) { if (def !== undefined) {
return def; return def;
} }
@ -1958,7 +1958,7 @@ function chmod_file(context, path, mode, callback) {
} }
} }
if (typeof mode != 'number') { if (typeof mode !== 'number') {
callback(new Errors.EINVAL('mode must be number', path)); callback(new Errors.EINVAL('mode must be number', path));
} }
else { else {
@ -1976,7 +1976,7 @@ function fchmod_file(context, ofd, mode, callback) {
} }
} }
if (typeof mode != 'number') { if (typeof mode !== 'number') {
callback(new Errors.EINVAL('mode must be a number')); callback(new Errors.EINVAL('mode must be a number'));
} }
else { else {

View File

@ -5,7 +5,6 @@ function Stats(path, fileNode, devName) {
this.dev = devName; this.dev = devName;
this.node = fileNode.id; this.node = fileNode.id;
this.type = fileNode.type; this.type = fileNode.type;
this.name = fileNode.name;
this.size = fileNode.size; this.size = fileNode.size;
this.nlinks = fileNode.nlinks; this.nlinks = fileNode.nlinks;
this.atime = fileNode.atime; this.atime = fileNode.atime;

View File

@ -26,7 +26,6 @@ describe("node.js tests: https://github.com/joyent/node/blob/master/test/simple/
done(); done();
} }
}); });
console.log('fn', fn);
fn.apply(fs, args); fn.apply(fs, args);
} }