From 330cd6b7ea46524783e5d1a8654153b459931cd7 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Tue, 1 Jun 2021 02:05:57 +0800 Subject: feat(cli): support URL overloads for `Deno.utime` and `Deno.utimeSync` (#10792) --- cli/dts/lib.deno.unstable.d.ts | 4 ++-- cli/tests/unit/utime_test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 0e5453554..f6e8aefd2 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -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; diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index 4e56ff193..32b631406 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -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 { + 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 { -- cgit v1.2.3