1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

feat(runtime): support URL overloads for Deno.symlink and Deno.symlinkSync (#10664)

This commit is contained in:
Casper Beyer 2021-06-03 22:16:00 +08:00 committed by GitHub
parent dc69b03339
commit ece56d9935
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 7 deletions

View file

@ -2379,8 +2379,8 @@ declare namespace Deno {
* *
* Requires `allow-write` permission. */ * Requires `allow-write` permission. */
export function symlinkSync( export function symlinkSync(
oldpath: string, oldpath: string | URL,
newpath: string, newpath: string | URL,
options?: SymlinkOptions, options?: SymlinkOptions,
): void; ): void;
@ -2396,8 +2396,8 @@ declare namespace Deno {
* *
* Requires `allow-write` permission. */ * Requires `allow-write` permission. */
export function symlink( export function symlink(
oldpath: string, oldpath: string | URL,
newpath: string, newpath: string | URL,
options?: SymlinkOptions, options?: SymlinkOptions,
): Promise<void>; ): Promise<void>;

View file

@ -1,5 +1,10 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertThrows, unitTest } from "./test_util.ts"; import {
assert,
assertThrows,
pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts";
unitTest( unitTest(
{ perms: { read: true, write: true } }, { perms: { read: true, write: true } },
@ -16,6 +21,24 @@ unitTest(
}, },
); );
unitTest(
{ perms: { read: true, write: true } },
function symlinkSyncURL(): void {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
Deno.mkdirSync(oldname);
Deno.symlinkSync(
pathToAbsoluteFileUrl(oldname),
pathToAbsoluteFileUrl(newname),
);
const newNameInfoLStat = Deno.lstatSync(newname);
const newNameInfoStat = Deno.statSync(newname);
assert(newNameInfoLStat.isSymlink);
assert(newNameInfoStat.isDirectory);
},
);
unitTest(function symlinkSyncPerm(): void { unitTest(function symlinkSyncPerm(): void {
assertThrows(() => { assertThrows(() => {
Deno.symlinkSync("oldbaddir", "newbaddir"); Deno.symlinkSync("oldbaddir", "newbaddir");
@ -36,3 +59,21 @@ unitTest(
assert(newNameInfoStat.isDirectory, "NOT DIRECTORY"); assert(newNameInfoStat.isDirectory, "NOT DIRECTORY");
}, },
); );
unitTest(
{ perms: { read: true, write: true } },
async function symlinkURL(): Promise<void> {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
Deno.mkdirSync(oldname);
await Deno.symlink(
pathToAbsoluteFileUrl(oldname),
pathToAbsoluteFileUrl(newname),
);
const newNameInfoLStat = Deno.lstatSync(newname);
const newNameInfoStat = Deno.statSync(newname);
assert(newNameInfoLStat.isSymlink, "NOT SYMLINK");
assert(newNameInfoStat.isDirectory, "NOT DIRECTORY");
},
);

View file

@ -344,7 +344,11 @@
newpath, newpath,
options, options,
) { ) {
core.opSync("op_symlink_sync", { oldpath, newpath, options }); core.opSync("op_symlink_sync", {
oldpath: pathFromURL(oldpath),
newpath: pathFromURL(newpath),
options,
});
} }
async function symlink( async function symlink(
@ -352,7 +356,11 @@
newpath, newpath,
options, options,
) { ) {
await core.opAsync("op_symlink_async", { oldpath, newpath, options }); await core.opAsync("op_symlink_async", {
oldpath: pathFromURL(oldpath),
newpath: pathFromURL(newpath),
options,
});
} }
function fdatasyncSync(rid) { function fdatasyncSync(rid) {