diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 4 | ||||
-rw-r--r-- | cli/rt/30_fs.js | 4 | ||||
-rw-r--r-- | cli/tests/unit/read_link_test.ts | 31 |
3 files changed, 35 insertions, 4 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 66718ea67..e42fb855d 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -1491,7 +1491,7 @@ declare namespace Deno { * Throws TypeError if called with a hard link * * Requires `allow-read` permission. */ - export function readLinkSync(path: string): string; + export function readLinkSync(path: string | URL): string; /** Resolves to the full path destination of the named symbolic link. * @@ -1503,7 +1503,7 @@ declare namespace Deno { * Throws TypeError if called with a hard link * * Requires `allow-read` permission. */ - export function readLink(path: string): Promise<string>; + export function readLink(path: string | URL): Promise<string>; /** Resolves to a `Deno.FileInfo` for the specified `path`. If `path` is a * symlink, information for the symlink will be returned instead of what it diff --git a/cli/rt/30_fs.js b/cli/rt/30_fs.js index 7c7d81c3b..33fab01e4 100644 --- a/cli/rt/30_fs.js +++ b/cli/rt/30_fs.js @@ -128,11 +128,11 @@ } function readLinkSync(path) { - return core.jsonOpSync("op_read_link_sync", { path }); + return core.jsonOpSync("op_read_link_sync", { path: pathFromURL(path) }); } function readLink(path) { - return core.jsonOpAsync("op_read_link_async", { path }); + return core.jsonOpAsync("op_read_link_async", { path: pathFromURL(path) }); } function realPathSync(path) { diff --git a/cli/tests/unit/read_link_test.ts b/cli/tests/unit/read_link_test.ts index 0e8390f6a..5be070ac5 100644 --- a/cli/tests/unit/read_link_test.ts +++ b/cli/tests/unit/read_link_test.ts @@ -3,6 +3,7 @@ import { assertEquals, assertThrows, assertThrowsAsync, + pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -21,6 +22,21 @@ unitTest( }, ); +unitTest( + { perms: { write: true, read: true } }, + function readLinkSyncUrlSuccess(): void { + const testDir = Deno.makeTempDirSync(); + const target = testDir + + (Deno.build.os == "windows" ? "\\target" : "/target"); + const symlink = testDir + + (Deno.build.os == "windows" ? "\\symlink" : "/symlink"); + Deno.mkdirSync(target); + Deno.symlinkSync(target, symlink); + const targetPath = Deno.readLinkSync(pathToAbsoluteFileUrl(symlink)); + assertEquals(targetPath, target); + }, +); + unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void { assertThrows(() => { Deno.readLinkSync("/symlink"); @@ -48,6 +64,21 @@ unitTest( }, ); +unitTest( + { perms: { write: true, read: true } }, + async function readLinkUrlSuccess(): Promise<void> { + const testDir = Deno.makeTempDirSync(); + const target = testDir + + (Deno.build.os == "windows" ? "\\target" : "/target"); + const symlink = testDir + + (Deno.build.os == "windows" ? "\\symlink" : "/symlink"); + Deno.mkdirSync(target); + Deno.symlinkSync(target, symlink); + const targetPath = await Deno.readLink(pathToAbsoluteFileUrl(symlink)); + assertEquals(targetPath, target); + }, +); + unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise< void > { |