Switch from .mode to .type on nodes

This commit is contained in:
David Humphrey 2018-05-24 14:32:27 -04:00
parent 2efb956411
commit 9244e9be6e
4 changed files with 35 additions and 35 deletions

View File

@ -108,9 +108,9 @@ function update_node_times(context, path, node, times, callback) {
*/ */
// in: file or directory path // in: file or directory path
// out: new node representing file/directory // out: new node representing file/directory
function make_node(context, path, mode, callback) { function make_node(context, path, type, callback) {
if(mode !== NODE_TYPE_DIRECTORY && mode !== NODE_TYPE_FILE) { if(type !== NODE_TYPE_DIRECTORY && type !== NODE_TYPE_FILE) {
return callback(new Errors.EINVAL('mode must be a directory or file', path)); return callback(new Errors.EINVAL('type must be a directory or file', path));
} }
path = normalize(path); path = normalize(path);
@ -125,7 +125,7 @@ function make_node(context, path, mode, callback) {
function create_node_in_parent(error, parentDirectoryNode) { function create_node_in_parent(error, parentDirectoryNode) {
if(error) { if(error) {
callback(error); callback(error);
} else if(parentDirectoryNode.mode !== NODE_TYPE_DIRECTORY) { } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY) {
callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path));
} else { } else {
parentNode = parentDirectoryNode; parentNode = parentDirectoryNode;
@ -153,7 +153,7 @@ function make_node(context, path, mode, callback) {
Node.create({ Node.create({
path: path, path: path,
guid: context.guid, guid: context.guid,
mode: mode type: type
}, function(error, result) { }, function(error, result) {
if(error) { if(error) {
callback(error); callback(error);
@ -181,7 +181,7 @@ function make_node(context, path, mode, callback) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
parentNodeData[name] = new DirectoryEntry(node.id, mode); parentNodeData[name] = new DirectoryEntry(node.id, type);
context.putObject(parentNode.data, parentNodeData, update_time); context.putObject(parentNode.data, parentNodeData, update_time);
} }
} }
@ -207,7 +207,7 @@ function find_node(context, path, callback) {
function read_root_directory_node(error, superNode) { function read_root_directory_node(error, superNode) {
if(error) { if(error) {
callback(error); callback(error);
} else if(!superNode || superNode.mode !== NODE_TYPE_META || !superNode.rnode) { } else if(!superNode || superNode.type !== NODE_TYPE_META || !superNode.rnode) {
callback(new Errors.EFILESYSTEMERROR()); callback(new Errors.EFILESYSTEMERROR());
} else { } else {
context.getObject(superNode.rnode, check_root_directory_node); context.getObject(superNode.rnode, check_root_directory_node);
@ -229,7 +229,7 @@ function find_node(context, path, callback) {
function read_parent_directory_data(error, parentDirectoryNode) { function read_parent_directory_data(error, parentDirectoryNode) {
if(error) { if(error) {
callback(error); callback(error);
} else if(parentDirectoryNode.mode !== NODE_TYPE_DIRECTORY || !parentDirectoryNode.data) { } else if(parentDirectoryNode.type !== NODE_TYPE_DIRECTORY || !parentDirectoryNode.data) {
callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path)); callback(new Errors.ENOTDIR('a component of the path prefix is not a directory', path));
} else { } else {
context.getObject(parentDirectoryNode.data, get_node_from_parent_directory_data); context.getObject(parentDirectoryNode.data, get_node_from_parent_directory_data);
@ -255,7 +255,7 @@ function find_node(context, path, callback) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
if(node.mode == 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));
@ -350,7 +350,7 @@ function ensure_root_directory(context, callback) {
Node.create({ Node.create({
guid: context.guid, guid: context.guid,
id: superNode.rnode, id: superNode.rnode,
mode: NODE_TYPE_DIRECTORY, type: NODE_TYPE_DIRECTORY,
path: ROOT_DIRECTORY_NAME path: ROOT_DIRECTORY_NAME
}, function(error, result) { }, function(error, result) {
if(error) { if(error) {
@ -415,7 +415,7 @@ function make_directory(context, path, callback) {
parentDirectoryData = result; parentDirectoryData = result;
Node.create({ Node.create({
guid: context.guid, guid: context.guid,
mode: NODE_TYPE_DIRECTORY, type: NODE_TYPE_DIRECTORY,
path: path path: path
}, function(error, result) { }, function(error, result) {
if(error) { if(error) {
@ -498,7 +498,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.mode != 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;
@ -578,7 +578,7 @@ function open_file(context, path, flags, callback) {
function read_directory_data(error, result) { function read_directory_data(error, result) {
if(error) { if(error) {
callback(error); callback(error);
} else if(result.mode !== NODE_TYPE_DIRECTORY) { } else if(result.type !== NODE_TYPE_DIRECTORY) {
callback(new Errors.ENOENT(null, path)); callback(new Errors.ENOENT(null, path));
} else { } else {
directoryNode = result; directoryNode = result;
@ -617,7 +617,7 @@ function open_file(context, path, flags, callback) {
callback(error); callback(error);
} else { } else {
var node = result; var node = result;
if(node.mode == 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));
@ -656,7 +656,7 @@ function open_file(context, path, flags, callback) {
function write_file_node() { function write_file_node() {
Node.create({ Node.create({
guid: context.guid, guid: context.guid,
mode: NODE_TYPE_FILE, type: NODE_TYPE_FILE,
path: path path: path
}, function(error, result) { }, function(error, result) {
if(error) { if(error) {
@ -847,7 +847,7 @@ function read_data(context, ofd, buffer, offset, length, position, callback) {
function read_file_data(error, result) { function read_file_data(error, result) {
if(error) { if(error) {
callback(error); callback(error);
} else if(result.mode === NODE_TYPE_DIRECTORY) { } else if(result.type === NODE_TYPE_DIRECTORY) {
callback(new Errors.EISDIR('the named file is a directory', ofd.path)); callback(new Errors.EISDIR('the named file is a directory', ofd.path));
} else { } else {
fileNode = result; fileNode = result;
@ -1046,7 +1046,7 @@ function unlink_node(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.mode === NODE_TYPE_DIRECTORY) { } else if(result.type === NODE_TYPE_DIRECTORY) {
callback(new Errors.EPERM('unlink not permitted on directories', name)); callback(new Errors.EPERM('unlink not permitted on directories', name));
} else { } else {
update_file_node(null, result); update_file_node(null, result);
@ -1098,7 +1098,7 @@ function read_directory(context, path, callback) {
function read_directory_data(error, result) { function read_directory_data(error, result) {
if(error) { if(error) {
callback(error); callback(error);
} else if(result.mode !== 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;
@ -1149,7 +1149,7 @@ function make_symbolic_link(context, srcpath, dstpath, callback) {
function write_file_node() { function write_file_node() {
Node.create({ Node.create({
guid: context.guid, guid: context.guid,
mode: NODE_TYPE_SYMBOLIC_LINK, type: NODE_TYPE_SYMBOLIC_LINK,
path: dstpath path: dstpath
}, function(error, result) { }, function(error, result) {
if(error) { if(error) {
@ -1219,7 +1219,7 @@ function read_link(context, path, callback) {
if(error) { if(error) {
callback(error); callback(error);
} else { } else {
if(result.mode != NODE_TYPE_SYMBOLIC_LINK) { if(result.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 {
callback(null, result.data); callback(null, result.data);
@ -1236,7 +1236,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.mode == 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;
@ -1292,7 +1292,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.mode == NODE_TYPE_DIRECTORY ) { } else if(node.type == NODE_TYPE_DIRECTORY ) {
callback(new Errors.EISDIR()); callback(new Errors.EISDIR());
} else{ } else{
fileNode = node; fileNode = node;
@ -1643,9 +1643,9 @@ function close(fs, context, fd, callback) {
} }
} }
function mknod(fs, context, path, mode, callback) { function mknod(fs, context, path, type, callback) {
if(!pathCheck(path, callback)) return; if(!pathCheck(path, callback)) return;
make_node(context, path, mode, callback); make_node(context, path, type, callback);
} }
function mkdir(fs, context, path, mode, callback) { function mkdir(fs, context, path, mode, callback) {
@ -2128,7 +2128,7 @@ function rename(fs, context, oldpath, newpath, callback) {
function check_node_type(error, node) { function check_node_type(error, node) {
if(error) { if(error) {
callback(error); callback(error);
} else if(node.mode === NODE_TYPE_DIRECTORY) { } else if(node.type === NODE_TYPE_DIRECTORY) {
find_node(context, oldParentPath, read_parent_directory_data); find_node(context, oldParentPath, read_parent_directory_data);
} else { } else {
link_node(context, oldpath, newpath, unlink_old_file); link_node(context, oldpath, newpath, unlink_old_file);

View File

@ -16,8 +16,8 @@ var S_IFREG = require('./constants.js').P9.S_IFREG;
var ROOT_DIRECTORY_NAME = require('./constants.js').ROOT_DIRECTORY_NAME; var ROOT_DIRECTORY_NAME = require('./constants.js').ROOT_DIRECTORY_NAME;
function getQType(mode) { function getQType(type) {
switch(mode) { switch(type) {
case NODE_TYPE_FILE: case NODE_TYPE_FILE:
return P9_QTFILE; return P9_QTFILE;
case NODE_TYPE_DIRECTORY: case NODE_TYPE_DIRECTORY:
@ -29,8 +29,8 @@ function getQType(mode) {
} }
} }
function getPOSIXMode(mode) { function getPOSIXMode(type) {
switch(mode) { switch(type) {
case NODE_TYPE_FILE: case NODE_TYPE_FILE:
return S_IFREG; return S_IFREG;
case NODE_TYPE_DIRECTORY: case NODE_TYPE_DIRECTORY:
@ -46,7 +46,7 @@ function Node(options) {
var now = Date.now(); var now = Date.now();
this.id = options.id; this.id = options.id;
this.mode = options.mode || NODE_TYPE_FILE; // node type (file, directory, etc) this.type = options.type || NODE_TYPE_FILE; // node type (file, directory, etc)
this.size = options.size || 0; // size (bytes for files, entries for directories) this.size = options.size || 0; // size (bytes for files, entries for directories)
this.atime = options.atime || now; // access time (will mirror ctime after creation) this.atime = options.atime || now; // access time (will mirror ctime after creation)
this.ctime = options.ctime || now; // creation/change time this.ctime = options.ctime || now; // creation/change time
@ -80,7 +80,7 @@ function Node(options) {
this.p9 = { this.p9 = {
qid: { qid: {
type: options.p9.qid.type || (getQType(this.mode) || P9_QTFILE), type: options.p9.qid.type || (getQType(this.type) || P9_QTFILE),
// use mtime for version info, since we already keep that updated // use mtime for version info, since we already keep that updated
version: options.p9.qid.now || now, version: options.p9.qid.now || now,
// files have a unique `path` number, which takes into account files with same // files have a unique `path` number, which takes into account files with same
@ -89,7 +89,7 @@ function Node(options) {
}, },
// permissions and flags // permissions and flags
// TODO: I don't think I'm doing this correctly yet... // TODO: I don't think I'm doing this correctly yet...
mode: options.p9.mode || (getPOSIXMode(this.mode) || S_IFREG), mode: options.p9.mode || (getPOSIXMode(this.type) || S_IFREG),
// Name of file/dir. Must be / if the file is the root directory of the server // Name of file/dir. Must be / if the file is the root directory of the server
// TODO: do I need this or can I derive it from abs path? // TODO: do I need this or can I derive it from abs path?
name: options.p9.name || (options.path === ROOT_DIRECTORY_NAME ? ROOT_DIRECTORY_NAME : path.basename(options.path)), name: options.p9.name || (options.path === ROOT_DIRECTORY_NAME ? ROOT_DIRECTORY_NAME : path.basename(options.path)),
@ -141,7 +141,7 @@ Node.create = function(options, callback) {
Node.fromObject = function(object) { Node.fromObject = function(object) {
return new Node({ return new Node({
id: object.id, id: object.id,
mode: object.mode, type: object.type,
size: object.size, size: object.size,
atime: object.atime, atime: object.atime,
ctime: object.ctime, ctime: object.ctime,

View File

@ -8,7 +8,7 @@ function Stats(fileNode, devName) {
this.atime = fileNode.atime; this.atime = fileNode.atime;
this.mtime = fileNode.mtime; this.mtime = fileNode.mtime;
this.ctime = fileNode.ctime; this.ctime = fileNode.ctime;
this.type = fileNode.mode; this.type = fileNode.type;
// Expose extra Plan 9 bits too // Expose extra Plan 9 bits too
this.p9 = fileNode.p9; this.p9 = fileNode.p9;
} }

View File

@ -4,7 +4,7 @@ function SuperNode(options) {
var now = Date.now(); var now = Date.now();
this.id = Constants.SUPER_NODE_ID; this.id = Constants.SUPER_NODE_ID;
this.mode = Constants.NODE_TYPE_META; this.type = Constants.NODE_TYPE_META;
this.atime = options.atime || now; this.atime = options.atime || now;
this.ctime = options.ctime || now; this.ctime = options.ctime || now;
this.mtime = options.mtime || now; this.mtime = options.mtime || now;