diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-24 09:03:45 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-02-01 15:52:29 +0800 |
commit | 5583981c5296be0383c934caf0c0ddd5e6bda379 (patch) | |
tree | 88694cd9b73bbe6890947f48d99409641d5ce9e3 /src | |
parent | 09da11e5e1a5578d583df3e7f18ecd9b6dd5caab (diff) | |
download | android-node-v8-5583981c5296be0383c934caf0c0ddd5e6bda379.tar.gz android-node-v8-5583981c5296be0383c934caf0c0ddd5e6bda379.tar.bz2 android-node-v8-5583981c5296be0383c934caf0c0ddd5e6bda379.zip |
fs: throw errors from fs.renameSync in JS
PR-URL: https://github.com/nodejs/node/pull/18348
Refs: https://github.com/nodejs/node/issues/18106
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_file.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index e193b53c73..073902ce7d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -688,19 +688,23 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) { static void Rename(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - CHECK_GE(args.Length(), 2); + int argc = args.Length(); + CHECK_GE(argc, 3); BufferValue old_path(env->isolate(), args[0]); CHECK_NE(*old_path, nullptr); BufferValue new_path(env->isolate(), args[1]); CHECK_NE(*new_path, nullptr); - if (args[2]->IsObject()) { - CHECK_EQ(args.Length(), 3); + if (args[2]->IsObject()) { // rename(old_path, new_path, req) + CHECK_EQ(argc, 3); AsyncDestCall(env, args, "rename", *new_path, new_path.length(), UTF8, AfterNoArgs, uv_fs_rename, *old_path, *new_path); - } else { - SYNC_DEST_CALL(rename, *old_path, *new_path, *old_path, *new_path) + } else { // rename(old_path, new_path, undefined, ctx) + CHECK_EQ(argc, 4); + fs_req_wrap req_wrap; + SyncCall(env, args[3], &req_wrap, "rename", + uv_fs_rename, *old_path, *new_path); } } |