emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

NODEFS can't FS.stat a link

Open ericmandel opened this issue 6 years ago • 3 comments

If I have a symlink on my local disk, using either relative or absolute paths:

Screen Shot 2020-04-13 at 2 01 12 PM

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:

Screen Shot 2020-04-13 at 2 00 13 PM

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 ...

ericmandel avatar Apr 13 '20 18:04 ericmandel

I think I might be running in to something similar. If I run FS.syncfs the symlinks appear to be working. But, my Application data is twice the size as normal in IDBFS. It is creating duplicates for every symlinked file in IDBFS. When the app reloads the symlinks are converted to their own directories and no longer linked.

EDIT: Just as I thought, there is no special handling for IDBFS. If you are using the node filesystem, there's probably no special handling there either. https://github.com/emscripten-core/emscripten/blob/master/src/library_idbfs.js#L153

I'll have to add special case for FS.lstat() and symlink results. Probably storing the destination in "contents" and relinking in storeLocalEntry.

ghost avatar Oct 13 '20 00:10 ghost

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

stale[bot] avatar Apr 17 '22 21:04 stale[bot]

bump

sbc100 avatar Apr 21 '22 17:04 sbc100