Skip to content

Commit a1f50a7

Browse files
authored
fix(node/fs): add utimes method to the FileHandle class (denoland#27582)
1 parent 9cb089f commit a1f50a7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ext/node/polyfills/internal/fs/handle.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ export class FileHandle extends EventEmitter {
157157
assertNotClosed(this, promises.chmod.name);
158158
return promises.chmod(this.#path, mode);
159159
}
160+
161+
utimes(
162+
atime: number | string | Date,
163+
mtime: number | string | Date,
164+
): Promise<void> {
165+
assertNotClosed(this, promises.utimes.name);
166+
return promises.utimes(this.#path, atime, mtime);
167+
}
160168
}
161169

162170
function assertNotClosed(handle: FileHandle, syscall: string) {

tests/unit_node/_fs/_fs_handle_test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,20 @@ Deno.test({
256256
await fileHandle.close();
257257
},
258258
});
259+
260+
Deno.test({
261+
name:
262+
"[node/fs filehandle.utimes] Change the file system timestamps of the file",
263+
async fn() {
264+
const fileHandle = await fs.open(testData);
265+
266+
const atime = new Date();
267+
const mtime = new Date(0);
268+
269+
await fileHandle.utimes(atime, mtime);
270+
assertEquals(Deno.statSync(testData).atime!, atime);
271+
assertEquals(Deno.statSync(testData).mtime!, mtime);
272+
273+
await fileHandle.close();
274+
},
275+
});

0 commit comments

Comments
 (0)