fs: throw fs.utimesSync errors in JS land
PR-URL: https://github.com/nodejs/node/pull/18871 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
8fb5a6cd81
commit
82523d3b6e
@ -1148,9 +1148,11 @@ fs.utimes = function(path, atime, mtime, callback) {
|
|||||||
fs.utimesSync = function(path, atime, mtime) {
|
fs.utimesSync = function(path, atime, mtime) {
|
||||||
path = getPathFromURL(path);
|
path = getPathFromURL(path);
|
||||||
validatePath(path);
|
validatePath(path);
|
||||||
|
const ctx = { path };
|
||||||
binding.utimes(pathModule.toNamespacedPath(path),
|
binding.utimes(pathModule.toNamespacedPath(path),
|
||||||
toUnixTimestamp(atime),
|
toUnixTimestamp(atime), toUnixTimestamp(mtime),
|
||||||
toUnixTimestamp(mtime));
|
undefined, ctx);
|
||||||
|
handleErrorFromBinding(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.futimes = function(fd, atime, mtime, callback) {
|
fs.futimes = function(fd, atime, mtime, callback) {
|
||||||
|
@ -1561,22 +1561,27 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void UTimes(const FunctionCallbackInfo<Value>& args) {
|
static void UTimes(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
|
||||||
CHECK_GE(args.Length(), 3);
|
const int argc = args.Length();
|
||||||
CHECK(args[1]->IsNumber());
|
CHECK_GE(argc, 3);
|
||||||
CHECK(args[2]->IsNumber());
|
|
||||||
|
|
||||||
BufferValue path(env->isolate(), args[0]);
|
BufferValue path(env->isolate(), args[0]);
|
||||||
CHECK_NE(*path, nullptr);
|
CHECK_NE(*path, nullptr);
|
||||||
|
|
||||||
const double atime = static_cast<double>(args[1]->NumberValue());
|
CHECK(args[1]->IsNumber());
|
||||||
const double mtime = static_cast<double>(args[2]->NumberValue());
|
const double atime = args[1].As<Number>()->Value();
|
||||||
|
|
||||||
|
CHECK(args[2]->IsNumber());
|
||||||
|
const double mtime = args[2].As<Number>()->Value();
|
||||||
|
|
||||||
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
|
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
|
||||||
if (req_wrap != nullptr) {
|
if (req_wrap != nullptr) { // utimes(path, atime, mtime, req)
|
||||||
AsyncCall(env, req_wrap, args, "utime", UTF8, AfterNoArgs,
|
AsyncCall(env, req_wrap, args, "utime", UTF8, AfterNoArgs,
|
||||||
uv_fs_utime, *path, atime, mtime);
|
uv_fs_utime, *path, atime, mtime);
|
||||||
} else {
|
} else { // utimes(path, atime, mtime, undefined, ctx)
|
||||||
SYNC_CALL(utime, *path, *path, atime, mtime);
|
CHECK_EQ(argc, 5);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[4], &req_wrap, "utime",
|
||||||
|
uv_fs_utime, *path, atime, mtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,3 +585,25 @@ if (!common.isWindows) {
|
|||||||
validateError
|
validateError
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// utimes
|
||||||
|
if (!common.isAIX) {
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, utime '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'utime');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.utimes(nonexistentFile, new Date(), new Date(),
|
||||||
|
common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.utimesSync(nonexistentFile, new Date(), new Date()),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user