Skip to content

Commit 9ced043

Browse files
authored
Fixed readlink not throwing EINVAL if the path was not a symlink (#215)
1 parent 1bfb7ac commit 9ced043

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/vfs/promises.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ export async function readlink(
10251025
options?: fs.BufferEncodingOption | fs.EncodingOption | string | null
10261026
): Promise<string | Buffer> {
10271027
await using handle = await _open(this, normalizePath(path), { flag: 'r', mode: 0o644, preserveSymlinks: true });
1028+
if (!isSymbolicLink(handle.inode)) throw new ErrnoError(Errno.EINVAL, 'Not a symbolic link: ' + path);
10281029
const value = await handle.readFile();
10291030
const encoding = typeof options == 'object' ? options?.encoding : options;
10301031
// always defaults to utf-8 to avoid wrangler (cloudflare) worker "unknown encoding" exception

tests/fs/links.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ suite('Links', () => {
2121
test('readlink', async () => {
2222
const destination = await fs.promises.readlink(symlink);
2323
assert.equal(destination, target);
24+
assert.throws(() => fs.readlinkSync(destination));
2425
});
2526

2627
test('read target contents', async () => {

0 commit comments

Comments
 (0)