From 4cfda74de4a3901828942e9418c43a434c0accf6 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Fri, 27 Jan 2012 15:33:25 -0800 Subject: [PATCH] uv.h: add EPERM to errno map to fix regression EPERM isn't mapped in so chown returns an unknown error. This is a regression from 0.4.12. philips:node/ (master*) $ cat chown.js var fs = require('fs') fs.chown("/tmp/foobar", 100, 100, function(er){ console.log(er);}) philips:node/ (master*) $ ls -la /tmp/foobar total 0 drwxr-xr-x 2 root wheel 68 Jan 24 17:21 . 0.4 --- philips:node/ (master*) $ /usr/local/Cellar/node/0.4.12/bin/node chown.js { stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'EPERM, Operation not permitted \'/tmp/foobar\'', errno: 1, code: 'EPERM', path: '/tmp/foobar' } master ------ philips:node/ (master*) $ ./node chown.js { [Error: UNKNOWN, unknown error '/tmp/foobar'] errno: -1, code: 'UNKNOWN', path: '/tmp/foobar' } AFTER ----- philips:node/ (master*) $ ./node chown.js { [Error: EPERM, operation not permitted '/tmp/foobar'] errno: 49, code: 'EPERM', path: '/tmp/foobar' } --- include/uv.h | 3 ++- src/unix/error.c | 1 + test/test-fs.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/uv.h b/include/uv.h index 62943527..23e5e21d 100644 --- a/include/uv.h +++ b/include/uv.h @@ -116,7 +116,8 @@ typedef intptr_t ssize_t; XX( 46, ESHUTDOWN, "") \ XX( 47, EEXIST, "file already exists") \ XX( 48, ESRCH, "no such process") \ - XX( 49, ENAMETOOLONG, "name too long") + XX( 49, ENAMETOOLONG, "name too long") \ + XX( 50, EPERM, "operation not permitted") #define UV_ERRNO_GEN(val, name, s) UV_##name = val, diff --git a/src/unix/error.c b/src/unix/error.c index 80d3270d..1d38623f 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -59,6 +59,7 @@ void uv_fatal_error(const int errorno, const char* syscall) { uv_err_code uv_translate_sys_error(int sys_errno) { switch (sys_errno) { case 0: return UV_OK; + case EPERM: return UV_EPERM; case ENOSYS: return UV_ENOSYS; case ENOTSOCK: return UV_ENOTSOCK; case ENOENT: return UV_ENOENT; diff --git a/test/test-fs.c b/test/test-fs.c index b88636b0..dbeb2a19 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -184,6 +184,13 @@ static void chown_cb(uv_fs_t* req) { uv_fs_req_cleanup(req); } +static void chown_root_cb(uv_fs_t* req) { + ASSERT(req->fs_type == UV_FS_CHOWN); + ASSERT(req->result == -1); + ASSERT(req->errorno == UV_EPERM); + chown_cb_count++; + uv_fs_req_cleanup(req); +} static void unlink_cb(uv_fs_t* req) { ASSERT(req == &unlink_req); @@ -1018,6 +1025,12 @@ TEST_IMPL(fs_chown) { uv_run(loop); ASSERT(chown_cb_count == 1); + /* chown to root (fail) */ + chown_cb_count = 0; + r = uv_fs_chown(loop, &req, "test_file", 0, 0, chown_root_cb); + uv_run(loop); + ASSERT(chown_cb_count == 1); + /* async fchown */ r = uv_fs_fchown(loop, &req, file, -1, -1, fchown_cb); ASSERT(r == 0);