2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-06 21:45:39 -04:00
|
|
|
|
2020-03-09 19:22:15 -04:00
|
|
|
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2019-08-23 01:30:14 -04:00
|
|
|
function toSecondsFromEpoch(v: number | Date): number {
|
2020-04-03 15:20:40 -04:00
|
|
|
return v instanceof Date ? Math.trunc(v.valueOf() / 1000) : v;
|
2019-05-01 05:08:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function utimeSync(
|
2020-03-06 11:29:23 -05:00
|
|
|
path: string,
|
2019-05-01 05:08:12 -04:00
|
|
|
atime: number | Date,
|
|
|
|
mtime: number | Date
|
|
|
|
): void {
|
2020-02-25 09:14:27 -05:00
|
|
|
sendSync("op_utime", {
|
2020-03-06 11:29:23 -05:00
|
|
|
path,
|
2019-08-23 01:30:14 -04:00
|
|
|
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
|
|
|
atime: toSecondsFromEpoch(atime),
|
2020-03-28 13:03:49 -04:00
|
|
|
mtime: toSecondsFromEpoch(mtime),
|
2019-08-23 01:30:14 -04:00
|
|
|
});
|
2019-05-01 05:08:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function utime(
|
2020-03-06 11:29:23 -05:00
|
|
|
path: string,
|
2019-05-01 05:08:12 -04:00
|
|
|
atime: number | Date,
|
|
|
|
mtime: number | Date
|
|
|
|
): Promise<void> {
|
2020-02-25 09:14:27 -05:00
|
|
|
await sendAsync("op_utime", {
|
2020-03-06 11:29:23 -05:00
|
|
|
path,
|
2019-08-23 01:30:14 -04:00
|
|
|
// TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
|
|
|
|
atime: toSecondsFromEpoch(atime),
|
2020-03-28 13:03:49 -04:00
|
|
|
mtime: toSecondsFromEpoch(mtime),
|
2019-08-23 01:30:14 -04:00
|
|
|
});
|
2019-05-01 05:08:12 -04:00
|
|
|
}
|