mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
feat(cli): support URL overloads for Deno.utime
and Deno.utimeSync
(#10792)
This commit is contained in:
parent
ea2c7ac556
commit
330cd6b7ea
3 changed files with 43 additions and 4 deletions
4
cli/dts/lib.deno.unstable.d.ts
vendored
4
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -766,7 +766,7 @@ declare namespace Deno {
|
|||
*
|
||||
* Requires `allow-write` permission. */
|
||||
export function utimeSync(
|
||||
path: string,
|
||||
path: string | URL,
|
||||
atime: number | Date,
|
||||
mtime: number | Date,
|
||||
): void;
|
||||
|
@ -783,7 +783,7 @@ declare namespace Deno {
|
|||
*
|
||||
* Requires `allow-write` permission. */
|
||||
export function utime(
|
||||
path: string,
|
||||
path: string | URL,
|
||||
atime: number | Date,
|
||||
mtime: number | Date,
|
||||
): Promise<void>;
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
assertEquals,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
pathToAbsoluteFileUrl,
|
||||
unitTest,
|
||||
} from "./test_util.ts";
|
||||
|
||||
|
@ -69,6 +70,25 @@ unitTest(
|
|||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
function utimeSyncUrlSuccess(): void {
|
||||
const testDir = Deno.makeTempDirSync();
|
||||
const filename = testDir + "/file.txt";
|
||||
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
||||
mode: 0o666,
|
||||
});
|
||||
|
||||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
Deno.utimeSync(pathToAbsoluteFileUrl(filename), atime, mtime);
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
function utimeSyncDirectorySuccess(): void {
|
||||
|
@ -177,6 +197,25 @@ unitTest(
|
|||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
async function utimeUrlSuccess(): Promise<void> {
|
||||
const testDir = Deno.makeTempDirSync();
|
||||
const filename = testDir + "/file.txt";
|
||||
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
||||
mode: 0o666,
|
||||
});
|
||||
|
||||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
await Deno.utime(pathToAbsoluteFileUrl(filename), atime, mtime);
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
||||
},
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
async function utimeDirectorySuccess(): Promise<void> {
|
||||
|
|
|
@ -315,7 +315,7 @@
|
|||
mtime,
|
||||
) {
|
||||
core.opSync("op_utime_sync", {
|
||||
path,
|
||||
path: pathFromURL(path),
|
||||
atime: toUnixTimeFromEpoch(atime),
|
||||
mtime: toUnixTimeFromEpoch(mtime),
|
||||
});
|
||||
|
@ -327,7 +327,7 @@
|
|||
mtime,
|
||||
) {
|
||||
await core.opAsync("op_utime_async", {
|
||||
path,
|
||||
path: pathFromURL(path),
|
||||
atime: toUnixTimeFromEpoch(atime),
|
||||
mtime: toUnixTimeFromEpoch(mtime),
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue