From e69a668e1f3d12f7b5f7f9022c79cfc23b831fee Mon Sep 17 00:00:00 2001 From: Daniel Osvaldo R Date: Thu, 26 Jun 2025 23:55:47 +0700 Subject: [PATCH] fix(ext/node): export promise based `lchown` and `lutimes` from `node:fs/promises` (#29870) The promised based `lchown` and `lutimes` were implemented in #24418 and #23172 , but haven't been exported through the `node:fs/promises` namespace. Signed-off-by: Daniel Osvaldo R --- ext/node/polyfills/fs/promises.ts | 4 ++-- tests/unit_node/fs_test.ts | 35 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ext/node/polyfills/fs/promises.ts b/ext/node/polyfills/fs/promises.ts index 281d7b6e00..7ebf770242 100644 --- a/ext/node/polyfills/fs/promises.ts +++ b/ext/node/polyfills/fs/promises.ts @@ -21,10 +21,10 @@ export const link = fsPromises.link; export const unlink = fsPromises.unlink; export const chmod = fsPromises.chmod; export const lchmod = fsPromises.lchmod; -// export const lchown = fs.lchown; +export const lchown = fsPromises.lchown; export const chown = fsPromises.chown; export const utimes = fsPromises.utimes; -// export const lutimes = fs.lutimes; +export const lutimes = fsPromises.lutimes; export const realpath = fsPromises.realpath; export const mkdtemp = fsPromises.mkdtemp; export const writeFile = fsPromises.writeFile; diff --git a/tests/unit_node/fs_test.ts b/tests/unit_node/fs_test.ts index 787fd7a932..7bf5306779 100644 --- a/tests/unit_node/fs_test.ts +++ b/tests/unit_node/fs_test.ts @@ -37,6 +37,8 @@ import { copyFile, cp, FileHandle, + lchown, + lutimes, open, stat, writeFile, @@ -407,3 +409,36 @@ Deno.test("[node/fs] fchmodSync works", { closeSync(fd); Deno.removeSync(tempFile); }); + +Deno.test("[node/fs/promises] lchown works", { + ignore: Deno.build.os === "windows", +}, async () => { + const tempFile = Deno.makeTempFileSync(); + const symlinkPath = tempFile + "-link"; + Deno.symlinkSync(tempFile, symlinkPath); + const uid = await execCmd("id -u"); + const gid = await execCmd("id -g"); + + await lchown(symlinkPath, +uid, +gid); + + Deno.removeSync(tempFile); + Deno.removeSync(symlinkPath); +}); + +Deno.test("[node/fs/promises] lutimes works", { + ignore: Deno.build.os === "windows", +}, async () => { + const tempFile = Deno.makeTempFileSync(); + const symlinkPath = tempFile + "-link"; + Deno.symlinkSync(tempFile, symlinkPath); + + const date = new Date("1970-01-01T00:00:00Z"); + await lutimes(symlinkPath, date, date); + + const stats = Deno.lstatSync(symlinkPath); + assertEquals((stats.atime as Date).getTime(), date.getTime()); + assertEquals((stats.mtime as Date).getTime(), date.getTime()); + + Deno.removeSync(tempFile); + Deno.removeSync(symlinkPath); +});