[njs] Improved handling of retvals of system function in "fs".
Dmitry Volyntsev
xeioex at nginx.com
Tue May 26 18:36:17 UTC 2020
details: https://hg.nginx.org/njs/rev/2e94c512d5c7
branches:
changeset: 1399:2e94c512d5c7
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue May 26 16:21:05 2020 +0000
description:
Improved handling of retvals of system function in "fs".
diffstat:
src/njs_fs.c | 30 ++++++++++--------------------
1 files changed, 10 insertions(+), 20 deletions(-)
diffs (82 lines):
diff -r d6fb90ffe4c9 -r 2e94c512d5c7 src/njs_fs.c
--- a/src/njs_fs.c Tue May 12 12:31:19 2020 +0300
+++ b/src/njs_fs.c Tue May 26 16:21:05 2020 +0000
@@ -458,16 +458,15 @@ njs_fs_rename_sync(njs_vm_t *vm, njs_val
return ret;
}
+ njs_set_undefined(&vm->retval);
+
ret = rename(old_path, new_path);
if (njs_slow_path(ret != 0)) {
- (void) njs_fs_error(vm, "rename", strerror(errno), NULL, errno,
+ ret = njs_fs_error(vm, "rename", strerror(errno), NULL, errno,
&vm->retval);
- return NJS_ERROR;
}
- njs_set_undefined(&vm->retval);
-
- return NJS_OK;
+ return ret;
}
@@ -515,16 +514,13 @@ njs_fs_access(njs_vm_t *vm, njs_value_t
return NJS_ERROR;
}
+ njs_set_undefined(&retval);
+
ret = access(file_path, md);
if (njs_slow_path(ret != 0)) {
ret = njs_fs_error(vm, "access", strerror(errno), path, errno, &retval);
- goto done;
}
- njs_set_undefined(&retval);
-
-done:
-
if (ret == NJS_OK) {
return njs_fs_result(vm, &retval, calltype, callback, 1);
}
@@ -573,17 +569,14 @@ njs_fs_symlink(njs_vm_t *vm, njs_value_t
return NJS_ERROR;
}
+ njs_set_undefined(&retval);
+
ret = symlink(target_path, file_path);
if (njs_slow_path(ret != 0)) {
ret = njs_fs_error(vm, "symlink", strerror(errno), path, errno,
&retval);
- goto done;
}
- njs_set_undefined(&retval);
-
-done:
-
if (ret == NJS_OK) {
return njs_fs_result(vm, &retval, calltype, callback, 1);
}
@@ -616,16 +609,13 @@ njs_fs_unlink(njs_vm_t *vm, njs_value_t
}
}
+ njs_set_undefined(&retval);
+
ret = unlink(file_path);
if (njs_slow_path(ret != 0)) {
ret = njs_fs_error(vm, "unlink", strerror(errno), path, errno, &retval);
- goto done;
}
- njs_set_undefined(&retval);
-
-done:
-
if (ret == NJS_OK) {
return njs_fs_result(vm, &retval, calltype, callback, 1);
}
More information about the nginx-devel
mailing list