Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
GH-853 fs.lchown and fs.lchmod
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 15, 2011
1 parent ca2ad16 commit fb4f777
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ fs.fchmodSync = function(fd, mode) {
return binding.fchmod(fd, modeNum(mode));
};

if (constants.hasOwnProperty('O_SYMLINK')) {
fs.lchmod = function(path, mode, callback) {
callback = callback || noop;
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function (err, fd) {
if (err) {
callback(err);
return;
}
fs.fchmod(fd, mode, callback);
});
};

fs.lchmodSync = function(path, mode) {
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
return fs.fchmodSync(fd, mode);
};
}


fs.chmod = function(path, mode, callback) {
binding.chmod(path, modeNum(mode), callback || noop);
};
Expand All @@ -448,6 +467,24 @@ fs.chmodSync = function(path, mode) {
return binding.chmod(path, modeNum(mode));
};

if (constants.hasOwnProperty('O_SYMLINK')) {
fs.lchown = function(path, uid, gid, callback) {
callback = callback || noop;
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function (err, fd) {
if (err) {
callback(err);
return;
}
fs.fchown(fd, uid, gid, callback);
});
};

fs.lchownSync = function(path, uid, gid) {
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
return fs.fchownSync(fd, uid, gid);
};
}

fs.fchown = function(fd, uid, gid, callback) {
binding.fchown(fd, uid, gid, callback || noop);
};
Expand Down
5 changes: 5 additions & 0 deletions src/node_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void DefineConstants(Handle<Object> target) {
NODE_DEFINE_CONSTANT(target, O_SYNC);
#endif

#ifdef O_SYMLINK
NODE_DEFINE_CONSTANT(target, O_SYMLINK);
#endif


#ifdef S_IRWXU
NODE_DEFINE_CONSTANT(target, S_IRWXU);
#endif
Expand Down

0 comments on commit fb4f777

Please sign in to comment.