Skip to content

Commit

Permalink
feat(node/fs): Add utimes method to the FileHandle class (denoland#25554
Browse files Browse the repository at this point in the history
)
  • Loading branch information
siaeyy committed Jan 8, 2025
1 parent cabdfa8 commit 07ce400
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/node/polyfills/internal/fs/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ export class FileHandle extends EventEmitter {
assertNotClosed(this, promises.chmod.name);
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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/unit_node/_fs/_fs_handle_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,21 @@ Deno.test({
await fileHandle.close();
},
});

Deno.test({
name:
"[node/fs filehandle.utimes] Change the file system timestamps of the file",
ignore: Deno.build.os === "windows",
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();
},
});

0 comments on commit 07ce400

Please sign in to comment.