emscripten-core / emscripten-core/emscripten
NODEFS can't FS.stat a link
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
If I have a symlink on my local disk, using either relative or absolute paths:

I can NODEFS mount a higher-level directory containing both the symlinks and the targets, and call FS.lstat() to find the size of the symlinks, but I get an error if I try to call FS.stat () to find the size of the targets:

Note that the symlinks point to targets within the mounted file system. Also, note that the mounted directory is an absolute path, not "." as in the examples.
This is the same problem I mentioned in #8721 regarding absolute vs relative mount points. That report is a little complicated, but points to code in library_nodefs.js/readlink:
````
readlink: function(node) {
var path = NODEFS.realPath(node);
try {
path = fs.readlinkSync(path);
=> path = NODEJS_PATH.relative(NODEJS_PATH.resolve(node.mount.opts.root), path);
return path;
} catch (e) {
if (!e.code) throw e;
throw new FS.ErrnoError(NODEFS.convertNodeCode(e));
}
},
````
In an old version of emscripten, I guessed that this line should be changed for absolute mount points:
````
// path = NODEJS_PATH.relative(NODEJS_PATH.resolve(node.mount.opts.root), path);
if( node.mount.mountpoint.charAt(0) === "/" ){
if( path.charAt(0) === "/" ){
path = node.mount.mountpoint + path;
}
} else {
path = NODEJS_PATH.relative(NODEJS_PATH.resolve(node.mount.opts.root), path);
}
````
I hesitated then, and still hesitate, to submit a PR because node.mount.mountpoint is not used in many places, so this doesn't quite seem to be the correct approach. (NB: nor have I tested the above since last year.)
Suggestions? I have a little time to work on this ...
Contributor guide
Assessment
This issue has not been assessed yet.