1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-19 04:16:00 -05:00

fix(node/fs): add utimes method to the FileHandle class (#27582)

This commit is contained in:
siaeyy 2025-01-14 12:08:22 +03:00 committed by GitHub
parent 9cb089f6db
commit a1f50a7422
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -157,6 +157,14 @@ export class FileHandle extends EventEmitter {
assertNotClosed(this, promises.chmod.name); assertNotClosed(this, promises.chmod.name);
return promises.chmod(this.#path, mode); return promises.chmod(this.#path, mode);
} }
utimes(
atime: number | string | Date,
mtime: number | string | Date,
): Promise<void> {
assertNotClosed(this, promises.utimes.name);
return promises.utimes(this.#path, atime, mtime);
}
} }
function assertNotClosed(handle: FileHandle, syscall: string) { function assertNotClosed(handle: FileHandle, syscall: string) {

View file

@ -256,3 +256,20 @@ Deno.test({
await fileHandle.close(); await fileHandle.close();
}, },
}); });
Deno.test({
name:
"[node/fs filehandle.utimes] Change the file system timestamps of the file",
async fn() {
const fileHandle = await fs.open(testData);
const atime = new Date();
const mtime = new Date(0);
await fileHandle.utimes(atime, mtime);
assertEquals(Deno.statSync(testData).atime!, atime);
assertEquals(Deno.statSync(testData).mtime!, mtime);
await fileHandle.close();
},
});