From 3935adced09cd557a836d00558b52d777b9a20a2 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 29 Mar 2011 16:34:05 -0700 Subject: [PATCH] GH-853 fs.lchown and fs.lchmod --- lib/fs.js | 37 +++++++++++++++++++++++++++++++++++++ src/node_constants.cc | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/lib/fs.js b/lib/fs.js index 2771ae1ab8..1ae45bb2c8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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); }; @@ -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); }; diff --git a/src/node_constants.cc b/src/node_constants.cc index 7d316ff107..1d14fcc60b 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -103,6 +103,11 @@ void DefineConstants(Handle 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