summaryrefslogtreecommitdiff
path: root/src/node_file.cc
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2014-12-15 10:44:46 -0500
committercjihrig <cjihrig@gmail.com>2014-12-15 12:05:49 -0500
commit165b70f146e163b82a09bb869463708516c08cf6 (patch)
treeb7e91ef9f5984838dd5bbaedec9cf24012e4fb3a /src/node_file.cc
parent524882faca28955aa5ef2a6194aab3895b0498b6 (diff)
downloadnode-new-165b70f146e163b82a09bb869463708516c08cf6.tar.gz
fs: add access() and accessSync()
fs.exists() and fs.existsSync() do not follow the typical error first callback convention. access() and accessSync() are added as alternatives in this commit. Fixes: https://github.com/joyent/node/pull/8714 PR-URL: https://github.com/iojs/io.js/pull/114 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Domenic Denicola <domenic@domenicdenicola.com>
Diffstat (limited to 'src/node_file.cc')
-rw-r--r--src/node_file.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 6aa09772bd..88b1262e16 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -165,6 +165,7 @@ static void After(uv_fs_t *req) {
switch (req->fs_type) {
// These all have no data to pass.
+ case UV_FS_ACCESS:
case UV_FS_CLOSE:
case UV_FS_RENAME:
case UV_FS_UNLINK:
@@ -317,6 +318,28 @@ struct fs_req_wrap {
#define SYNC_RESULT err
+static void Access(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args.GetIsolate());
+ HandleScope scope(env->isolate());
+
+ if (args.Length() < 2)
+ return THROW_BAD_ARGS;
+ if (!args[0]->IsString())
+ return TYPE_ERROR("path must be a string");
+ if (!args[1]->IsInt32())
+ return TYPE_ERROR("mode must be an integer");
+
+ node::Utf8Value path(args[0]);
+ int mode = static_cast<int>(args[1]->Int32Value());
+
+ if (args[2]->IsObject()) {
+ ASYNC_CALL(access, args[2], *path, mode);
+ } else {
+ SYNC_CALL(access, *path, *path, mode);
+ }
+}
+
+
static void Close(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
@@ -1112,6 +1135,7 @@ void InitFs(Handle<Object> target,
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "FSInitialize"),
env->NewFunctionTemplate(FSInitialize)->GetFunction());
+ env->SetMethod(target, "access", Access);
env->SetMethod(target, "close", Close);
env->SetMethod(target, "open", Open);
env->SetMethod(target, "read", Read);