GH-853 fs.lchown and fs.lchmod
authorisaacs <i@izs.me>
Tue, 29 Mar 2011 23:34:05 +0000 (16:34 -0700)
committerisaacs <i@izs.me>
Wed, 20 Apr 2011 23:04:39 +0000 (16:04 -0700)
lib/fs.js
src/node_constants.cc

index 2771ae1..1ae45bb 100644 (file)
--- 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);
 };
index 7d316ff..1d14fcc 100644 (file)
@@ -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