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:
parent
9cb089f6db
commit
a1f50a7422
2 changed files with 25 additions and 0 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue