From 374300ca8d1a97989b9c50f8cc8f3ed893e3bdd8 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Sat, 27 Feb 2010 18:18:41 +0100 Subject: [PATCH] Updated patch of node.cc for supporting reading of umask --- doc/api.txt | 9 +++++---- src/node.cc | 14 +++++++++----- test/simple/test-umask.js | 8 +++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/doc/api.txt b/doc/api.txt index 1815dfd695..752eecf165 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -143,10 +143,11 @@ Gets/sets the group identity of the process. (See setgid(2).) +process.chdir(directory)+:: Changes the current working directory of the process. -+process.umask(mask)+ :: -Sets the process's file mode creation mask. Child processes inherit the mask -from the parent process. - - returns the old mask. ++process.umask([mask])+ :: +Sets or read the process's file mode creation mask. Child processes inherit +the mask from the parent process. + - returns the old mask if +mask+ argument is given, otherwise returns +the current mask. +process.kill(pid, signal="SIGTERM")+ :: Send a signal to a process. +pid+ is the process id and +signal+ is the diff --git a/src/node.cc b/src/node.cc index 4af11e2c48..f76e4267d7 100644 --- a/src/node.cc +++ b/src/node.cc @@ -471,14 +471,18 @@ static Handle Cwd(const Arguments& args) { static Handle Umask(const Arguments& args){ HandleScope scope; - - if(args.Length() < 1 || !args[0]->IsInt32()) { + unsigned int old; + if(args.Length() < 1) { + old = umask(0); + umask((mode_t)old); + } + else if(!args[0]->IsInt32()) { return ThrowException(Exception::TypeError( String::New("argument must be an integer."))); } - unsigned int mask = args[0]->Uint32Value(); - unsigned int old = umask((mode_t)mask); - + else { + old = umask((mode_t)args[0]->Uint32Value()); + } return scope.Close(Uint32::New(old)); } diff --git a/test/simple/test-umask.js b/test/simple/test-umask.js index 5509cd132c..8674642bae 100644 --- a/test/simple/test-umask.js +++ b/test/simple/test-umask.js @@ -3,4 +3,10 @@ process.mixin(require("../common")); var mask = 0664; var old = process.umask(mask); -assert.equal(true, mask === process.umask(old)); +assert.equal(mask, process.umask(old)); + +// confirm reading the umask does not modify it. +// 1. If the test fails, this call will succeed, but the mask will be set to 0 +assert.equal(old, process.umask()); +// 2. If the test fails, process.umask() will return 0 +assert.equal(old, process.umask());