summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/dts/lib.deno.unstable.d.ts4
-rw-r--r--cli/tests/unit/utime_test.ts39
-rw-r--r--runtime/js/30_fs.js4
3 files changed, 43 insertions, 4 deletions
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<void>;
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";
@@ -71,6 +72,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 {
const testDir = Deno.makeTempDirSync();
@@ -179,6 +199,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> {
const testDir = Deno.makeTempDirSync();
diff --git a/runtime/js/30_fs.js b/runtime/js/30_fs.js
index 67c3d4a1f..11e9b32ef 100644
--- a/runtime/js/30_fs.js
+++ b/runtime/js/30_fs.js
@@ -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),
});