Deal with file type bits in mode when setting permissions via chmod

This commit is contained in:
David Humphrey 2018-05-29 13:47:16 -04:00
parent 4e73ef8d9b
commit 1087371fc4
2 changed files with 10 additions and 5 deletions

View File

@ -1953,7 +1953,7 @@ function chmod_file(context, path, mode, callback) {
if (error) {
callback(error);
} else {
node.mode = mode;
Node.setMode(mode, node);
update_node_times(context, path, node, { mtime: Date.now() }, callback);
}
}

View File

@ -12,17 +12,17 @@ var S_IFLNK = require('./constants.js').S_IFLNK;
var DEFAULT_FILE_PERMISSIONS = require('./constants.js').DEFAULT_FILE_PERMISSIONS;
var DEFAULT_DIR_PERMISSIONS = require('./constants.js').DEFAULT_DIR_PERMISSIONS;
function getMode(type) {
function getMode(type, mode) {
switch(type) {
case NODE_TYPE_DIRECTORY:
return DEFAULT_DIR_PERMISSIONS | S_IFDIR;
return (mode || DEFAULT_DIR_PERMISSIONS) | S_IFDIR;
case NODE_TYPE_SYMBOLIC_LINK:
return DEFAULT_FILE_PERMISSIONS | S_IFLNK;
return (mode || DEFAULT_FILE_PERMISSIONS) | S_IFLNK;
/* jshint -W086 */
case NODE_TYPE_FILE:
// falls through
default:
return DEFAULT_FILE_PERMISSIONS | S_IFREG;
return (mode || DEFAULT_FILE_PERMISSIONS) | S_IFREG;
}
}
@ -79,4 +79,9 @@ Node.create = function(options, callback) {
});
};
// Update the node's mode (permissions), taking file type bits into account.
Node.setMode = function(mode, node) {
node.mode = getMode(node.type, mode);
};
module.exports = Node;