fs: implement lutimes · nodejs/node@a19933f · GitHub
Skip to content

Commit a19933f

Browse files
arcanisaddaleax
authored andcommitted
fs: implement lutimes
PR-URL: #33399 Backport-PR-URL: #35320 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 232f6e1 commit a19933f

5 files changed

Lines changed: 159 additions & 28 deletions

File tree

doc/api/fs.md

Lines changed: 51 additions & 0 deletions

lib/fs.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,28 @@ function futimesSync(fd, atime, mtime) {
13031303
handleErrorFromBinding(ctx);
13041304
}
13051305

1306+
function lutimes(path, atime, mtime, callback) {
1307+
callback = makeCallback(callback);
1308+
path = getValidatedPath(path);
1309+
1310+
const req = new FSReqCallback();
1311+
req.oncomplete = callback;
1312+
binding.lutimes(pathModule.toNamespacedPath(path),
1313+
toUnixTimestamp(atime),
1314+
toUnixTimestamp(mtime),
1315+
req);
1316+
}
1317+
1318+
function lutimesSync(path, atime, mtime) {
1319+
path = getValidatedPath(path);
1320+
const ctx = { path };
1321+
binding.lutimes(pathModule.toNamespacedPath(path),
1322+
toUnixTimestamp(atime),
1323+
toUnixTimestamp(mtime),
1324+
undefined, ctx);
1325+
handleErrorFromBinding(ctx);
1326+
}
1327+
13061328
function writeAll(fd, isUserFd, buffer, offset, length, callback) {
13071329
// write(fd, buffer, offset, length, position, callback)
13081330
fs.write(fd, buffer, offset, length, null, (writeErr, written) => {
@@ -1938,6 +1960,8 @@ module.exports = fs = {
19381960
linkSync,
19391961
lstat,
19401962
lstatSync,
1963+
lutimes,
1964+
lutimesSync,
19411965
mkdir,
19421966
mkdirSync,
19431967
mkdtemp,

lib/internal/fs/promises.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ async function futimes(handle, atime, mtime) {
474474
return binding.futimes(handle.fd, atime, mtime, kUsePromises);
475475
}
476476

477+
async function lutimes(path, atime, mtime) {
478+
path = getValidatedPath(path);
479+
return binding.lutimes(pathModule.toNamespacedPath(path),
480+
toUnixTimestamp(atime),
481+
toUnixTimestamp(mtime),
482+
kUsePromises);
483+
}
484+
477485
async function realpath(path, options) {
478486
options = getOptions(options, {});
479487
path = getValidatedPath(path);
@@ -541,6 +549,7 @@ module.exports = {
541549
lchown,
542550
chown,
543551
utimes,
552+
lutimes,
544553
realpath,
545554
mkdtemp,
546555
writeFile,

src/node_file.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,35 @@ static void FUTimes(const FunctionCallbackInfo<Value>& args) {
22472247
}
22482248
}
22492249

2250+
static void LUTimes(const FunctionCallbackInfo<Value>& args) {
2251+
Environment* env = Environment::GetCurrent(args);
2252+
2253+
const int argc = args.Length();
2254+
CHECK_GE(argc, 3);
2255+
2256+
BufferValue path(env->isolate(), args[0]);
2257+
CHECK_NOT_NULL(*path);
2258+
2259+
CHECK(args[1]->IsNumber());
2260+
const double atime = args[1].As<Number>()->Value();
2261+
2262+
CHECK(args[2]->IsNumber());
2263+
const double mtime = args[2].As<Number>()->Value();
2264+
2265+
FSReqBase* req_wrap_async = GetReqWrap(env, args[3]);
2266+
if (req_wrap_async != nullptr) { // lutimes(path, atime, mtime, req)
2267+
AsyncCall(env, req_wrap_async, args, "lutime", UTF8, AfterNoArgs,
2268+
uv_fs_lutime, *path, atime, mtime);
2269+
} else { // lutimes(path, atime, mtime, undefined, ctx)
2270+
CHECK_EQ(argc, 5);
2271+
FSReqWrapSync req_wrap_sync;
2272+
FS_SYNC_TRACE_BEGIN(lutimes);
2273+
SyncCall(env, args[4], &req_wrap_sync, "lutime",
2274+
uv_fs_lutime, *path, atime, mtime);
2275+
FS_SYNC_TRACE_END(lutimes);
2276+
}
2277+
}
2278+
22502279
static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
22512280
Environment* env = Environment::GetCurrent(args);
22522281
Isolate* isolate = env->isolate();
@@ -2329,6 +2358,7 @@ void Initialize(Local<Object> target,
23292358

23302359
env->SetMethod(target, "utimes", UTimes);
23312360
env->SetMethod(target, "futimes", FUTimes);
2361+
env->SetMethod(target, "lutimes", LUTimes);
23322362

23332363
env->SetMethod(target, "mkdtemp", Mkdtemp);
23342364

test/parallel/test-fs-utimes.js

Lines changed: 45 additions & 28 deletions

0 commit comments

Comments
 (0)