Skip to content

πŸ› Bug Report β€” Runtime APIs: node:fs: lstat, readlink, readdir and realpath fail on paths through a symlinked directoryΒ #8811

Open

Description

@FarinM

When a path uses a directory that is symlinked, lstat, readlink, readdir and realpath all fail or return the wrong result, while Node.js follows the link. readFile and stat on the same paths already work. I tested it on workerd 1.20261121.1.

fs.mkdirSync('/tmp/r/store/pkg', { recursive: true });
fs.writeFileSync('/tmp/r/store/pkg/package.json', '{}');
fs.symlinkSync('/tmp/r/store/pkg/package.json', '/tmp/r/store/pkg/main');
fs.mkdirSync('/tmp/r/node_modules');
fs.symlinkSync('/tmp/r/store/pkg', '/tmp/r/node_modules/pkg');
fs.symlinkSync('/tmp/r/node_modules/pkg', '/tmp/r/again');

// Node.js returns the file's stats, workerd errors with ENOENT
fs.lstatSync('/tmp/r/node_modules/pkg/package.json');
// Node.js returns '/tmp/r/store/pkg/package.json', workerd errors with ENOENT
fs.readlinkSync('/tmp/r/node_modules/pkg/main');
// Node.js returns ['main', 'package.json'], workerd errors with EINVAL
fs.readdirSync('/tmp/r/node_modules/pkg');
// Node.js returns '/tmp/r/store/pkg/package.json', workerd errors with ENOENT
fs.realpathSync('/tmp/r/node_modules/pkg/package.json');
// Node.js returns '/tmp/r/store/pkg', workerd returns '/tmp/r/node_modules/pkg'
fs.realpathSync('/tmp/r/again');

The problem is that none of these calls follow a link in the middle of a path. readdir also doesn't follow a link at the end of the path, and realpath resolves at most one link. This for instance breaks pnpm-like layouts, where all the packages are links.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions