2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 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-06-24 18:57:08 -04:00
|
|
|
} from "./test_util.ts";
|
2018-09-25 00:20:49 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { 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
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { 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-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { 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-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { read: true } }, function readLinkSyncNotFound() {
|
2021-10-11 09:21:18 -04:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
Deno.readLinkSync("bad_filename");
|
|
|
|
},
|
|
|
|
Deno.errors.NotFound,
|
|
|
|
`readlink 'bad_filename'`,
|
|
|
|
);
|
2018-09-25 00:20:49 -04:00
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { 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
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { 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-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { 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
|
|
|
});
|
2021-10-11 09:21:18 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { read: true } }, async function readLinkNotFound() {
|
2021-10-11 09:21:18 -04:00
|
|
|
await assertRejects(
|
|
|
|
async () => {
|
|
|
|
await Deno.readLink("bad_filename");
|
|
|
|
},
|
|
|
|
Deno.errors.NotFound,
|
|
|
|
`readlink 'bad_filename'`,
|
|
|
|
);
|
|
|
|
});
|