Skip to content

Commit 3935adc

Browse files
committed
nodejsGH-853 fs.lchown and fs.lchmod
1 parent 5cfac21 commit 3935adc

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/fs.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,25 @@ fs.fchmodSync = function(fd, mode) {
440440
return binding.fchmod(fd, modeNum(mode));
441441
};
442442

443+
if (constants.hasOwnProperty('O_SYMLINK')) {
444+
fs.lchmod = function(path, mode, callback) {
445+
callback = callback || noop;
446+
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function (err, fd) {
447+
if (err) {
448+
callback(err);
449+
return;
450+
}
451+
fs.fchmod(fd, mode, callback);
452+
});
453+
};
454+
455+
fs.lchmodSync = function(path, mode) {
456+
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
457+
return fs.fchmodSync(fd, mode);
458+
};
459+
}
460+
461+
443462
fs.chmod = function(path, mode, callback) {
444463
binding.chmod(path, modeNum(mode), callback || noop);
445464
};
@@ -448,6 +467,24 @@ fs.chmodSync = function(path, mode) {
448467
return binding.chmod(path, modeNum(mode));
449468
};
450469

470+
if (constants.hasOwnProperty('O_SYMLINK')) {
471+
fs.lchown = function(path, uid, gid, callback) {
472+
callback = callback || noop;
473+
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function (err, fd) {
474+
if (err) {
475+
callback(err);
476+
return;
477+
}
478+
fs.fchown(fd, uid, gid, callback);
479+
});
480+
};
481+
482+
fs.lchownSync = function(path, uid, gid) {
483+
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK);
484+
return fs.fchownSync(fd, uid, gid);
485+
};
486+
}
487+
451488
fs.fchown = function(fd, uid, gid, callback) {
452489
binding.fchown(fd, uid, gid, callback || noop);
453490
};

src/node_constants.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ void DefineConstants(Handle<Object> target) {
103103
NODE_DEFINE_CONSTANT(target, O_SYNC);
104104
#endif
105105

106+
#ifdef O_SYMLINK
107+
NODE_DEFINE_CONSTANT(target, O_SYMLINK);
108+
#endif
109+
110+
106111
#ifdef S_IRWXU
107112
NODE_DEFINE_CONSTANT(target, S_IRWXU);
108113
#endif

0 commit comments

Comments
 (0)