mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
This commit is contained in:
parent
2426174485
commit
0db04d6a42
2 changed files with 52 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
|||
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
||||
|
||||
function toSecondsFromEpoch(v: number | Date): number {
|
||||
return v instanceof Date ? v.valueOf() / 1000 : v;
|
||||
return v instanceof Date ? Math.trunc(v.valueOf() / 1000) : v;
|
||||
}
|
||||
|
||||
export function utimeSync(
|
||||
|
|
|
@ -58,6 +58,31 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
function utimeSyncFileDateSuccess() {
|
||||
const testDir = Deno.makeTempDirSync();
|
||||
const filename = testDir + "/file.txt";
|
||||
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
||||
mode: 0o666,
|
||||
});
|
||||
const atime = new Date();
|
||||
const mtime = new Date();
|
||||
Deno.utimeSync(filename, atime, mtime);
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
// atime and mtime must be scaled by a factor of 1000 to be recorded in seconds
|
||||
assertFuzzyTimestampEquals(
|
||||
fileInfo.accessed,
|
||||
Math.trunc(atime.valueOf() / 1000)
|
||||
);
|
||||
assertFuzzyTimestampEquals(
|
||||
fileInfo.modified,
|
||||
Math.trunc(mtime.valueOf() / 1000)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
function utimeSyncLargeNumberSuccess(): void {
|
||||
|
@ -158,6 +183,32 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
async function utimeFileDateSuccess(): Promise<void> {
|
||||
const testDir = Deno.makeTempDirSync();
|
||||
const filename = testDir + "/file.txt";
|
||||
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
||||
mode: 0o666,
|
||||
});
|
||||
|
||||
const atime = new Date();
|
||||
const mtime = new Date();
|
||||
await Deno.utime(filename, atime, mtime);
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
// The dates must be scaled by a factored of 1000 to make them seconds
|
||||
assertFuzzyTimestampEquals(
|
||||
fileInfo.accessed,
|
||||
Math.trunc(atime.valueOf() / 1000)
|
||||
);
|
||||
assertFuzzyTimestampEquals(
|
||||
fileInfo.modified,
|
||||
Math.trunc(mtime.valueOf() / 1000)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
async function utimeNotFound(): Promise<void> {
|
||||
|
|
Loading…
Add table
Reference in a new issue