mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(cli): add file URL support for Deno.readLink (#8423)
This commit is contained in:
parent
46850918e7
commit
266925d772
3 changed files with 35 additions and 4 deletions
4
cli/dts/lib.deno.ns.d.ts
vendored
4
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -1491,7 +1491,7 @@ declare namespace Deno {
|
||||||
* Throws TypeError if called with a hard link
|
* Throws TypeError if called with a hard link
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* 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.
|
/** 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
|
* Throws TypeError if called with a hard link
|
||||||
*
|
*
|
||||||
* Requires `allow-read` permission. */
|
* 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
|
/** 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
|
* symlink, information for the symlink will be returned instead of what it
|
||||||
|
|
|
@ -128,11 +128,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function readLinkSync(path) {
|
function readLinkSync(path) {
|
||||||
return core.jsonOpSync("op_read_link_sync", { path });
|
return core.jsonOpSync("op_read_link_sync", { path: pathFromURL(path) });
|
||||||
}
|
}
|
||||||
|
|
||||||
function readLink(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) {
|
function realPathSync(path) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
assertThrowsAsync,
|
assertThrowsAsync,
|
||||||
|
pathToAbsoluteFileUrl,
|
||||||
unitTest,
|
unitTest,
|
||||||
} from "./test_util.ts";
|
} 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 {
|
unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void {
|
||||||
assertThrows(() => {
|
assertThrows(() => {
|
||||||
Deno.readLinkSync("/symlink");
|
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<
|
unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise<
|
||||||
void
|
void
|
||||||
> {
|
> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue