return binding.chmod(path, mode);
};
+fs.chown = function(path, uid, gid, callback) {
+ binding.chown(path, uid, gid, callback || noop);
+};
+
+fs.chownSync = function(path, uid, gid) {
+ return binding.chown(path, uid, gid);
+};
+
function writeAll (fd, data, encoding, callback) {
fs.write(fd, data, 0, encoding, function (writeErr, written) {
if (writeErr) {
case EIO_READLINK:
case EIO_OPEN:
case EIO_CHMOD:
+ case EIO_CHOWN:
case EIO_MKDIR:
argv[0] = ErrnoException(req->errorno, NULL, "", static_cast<const char*>(req->ptr1));
break;
case EIO_LINK:
case EIO_SYMLINK:
case EIO_CHMOD:
+ case EIO_CHOWN:
argc = 0;
break;
}
}
+
/* fs.chmod(fd, mode);
* Wrapper for chmod(1) / EIO_CHMOD
*/
-static Handle<Value> Chmod(const Arguments& args){
+static Handle<Value> Chmod(const Arguments& args) {
HandleScope scope;
-
+
if(args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
return THROW_BAD_ARGS;
}
String::Utf8Value path(args[0]->ToString());
mode_t mode = static_cast<mode_t>(args[1]->Int32Value());
-
+
if(args[2]->IsFunction()) {
ASYNC_CALL(chmod, args[2], *path, mode);
} else {
}
+/* fs.chown(fd, uid, gid);
+ * Wrapper for chown(1) / EIO_CHOWN
+ */
+static Handle<Value> Chown(const Arguments& args) {
+ HandleScope scope;
+
+ if (args.Length() < 3 || !args[0]->IsString()) {
+ return THROW_BAD_ARGS;
+ }
+
+ if (!args[1]->IsInt32() || !args[2]->IsInt32()) {
+ return ThrowException(Exception::Error(String::New("User and Group IDs must be an integer.")));
+ }
+
+ String::Utf8Value path(args[0]->ToString());
+ uid_t uid = static_cast<uid_t>(args[1]->Int32Value());
+ gid_t gid = static_cast<gid_t>(args[2]->Int32Value());
+
+ if (args[3]->IsFunction()) {
+ ASYNC_CALL(chown, args[3], *path, uid, gid);
+ } else {
+ int ret = chown(*path, uid, gid);
+ if (ret != 0) return ThrowException(ErrnoException(errno, NULL, "", *path));
+ return Undefined();
+ }
+}
+
void File::Initialize(Handle<Object> target) {
HandleScope scope;
NODE_SET_METHOD(target, "write", Write);
NODE_SET_METHOD(target, "chmod", Chmod);
+ NODE_SET_METHOD(target, "chown", Chown);
errno_symbol = NODE_PSYMBOL("errno");
encoding_symbol = NODE_PSYMBOL("node:encoding");