2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-06-24 18:57:08 -04:00
|
|
|
import {
|
|
|
|
assertEquals,
|
2021-09-22 09:21:11 -04:00
|
|
|
assertRejects,
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows,
|
2020-11-23 16:11:56 -05:00
|
|
|
pathToAbsoluteFileUrl,
|
2020-09-27 06:22:32 -04:00
|
|
|
unitTest,
|
2020-06-24 18:57:08 -04:00
|
|
|
} from "./test_util.ts";
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function readLinkSyncSuccess() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2020-07-14 15:24:17 -04:00
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.mkdirSync(target);
|
2020-06-25 07:27:23 -04:00
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = Deno.readLinkSync(symlink);
|
|
|
|
assertEquals(targetPath, target);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2020-11-23 16:11:56 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function readLinkSyncUrlSuccess() {
|
2020-11-23 16:11:56 -05:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest({ perms: { read: false } }, function readLinkSyncPerm() {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-04-29 16:39:37 -04:00
|
|
|
Deno.readLinkSync("/symlink");
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2019-02-08 15:59:38 -05:00
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest({ perms: { read: true } }, function readLinkSyncNotFound() {
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
|
|
|
Deno.readLinkSync("bad_filename");
|
|
|
|
}, Deno.errors.NotFound);
|
2018-09-25 00:20:49 -04:00
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function readLinkSuccess() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2020-07-14 15:24:17 -04:00
|
|
|
const target = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\target" : "/target");
|
|
|
|
const symlink = testDir +
|
|
|
|
(Deno.build.os == "windows" ? "\\symlink" : "/symlink");
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.mkdirSync(target);
|
2020-06-25 07:27:23 -04:00
|
|
|
Deno.symlinkSync(target, symlink);
|
|
|
|
const targetPath = await Deno.readLink(symlink);
|
|
|
|
assertEquals(targetPath, target);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-02-08 15:59:38 -05:00
|
|
|
|
2020-11-23 16:11:56 -05:00
|
|
|
unitTest(
|
|
|
|
{ perms: { write: true, read: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function readLinkUrlSuccess() {
|
2020-11-23 16:11:56 -05:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest({ perms: { read: false } }, async function readLinkPerm() {
|
2021-09-22 09:21:11 -04:00
|
|
|
await assertRejects(async () => {
|
2020-04-29 16:39:37 -04:00
|
|
|
await Deno.readLink("/symlink");
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2019-02-08 15:59:38 -05:00
|
|
|
});
|