emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Fix retrieval of mounted directory names

Open guusw opened this issue 8 months ago • 5 comments
trafficstars

As mentioned in #18112 I decided to PR my changes since I would like to use upstream emscripten for development where possible.

Basically retrieval of the CWD for mounted directories (e.g. fetchfs) will not return the correct name for the mounted directory, for example // instead of /http_fs/

guusw avatar Feb 25 '25 07:02 guusw

Can you add a test for this? That might also help me understand the problem we are solving here.

sbc100 avatar Feb 25 '25 17:02 sbc100

Added a test, seems like it can be reproduced with just memory backend too

4.0.1:

WasmFS Mounted Directory CWD Test
Initial CWD: /
CWD after chdir("/tfs"): /
Aborted(Assertion failed: strcmp(buf, "/tfs") == 0, at: /Users/bakje.coffee/Projects/emscripten/test/wasmfs/wasmfs_mounted_cwd.c,36,main)
/Users/bakje.coffee/Projects/emscripten/out/test/wasmfs_mounted_cwd.js:684
  var e = new WebAssembly.RuntimeError(what);

After PR works fine

guusw avatar Feb 26 '25 08:02 guusw

I recently updated test_unistd_unlink in test_core.py such this it skips under wasmfs due to this bug.. can you remove the skipTest there as part of this PR?

sbc100 avatar Mar 08 '25 00:03 sbc100

Part of the documented requirements for a backend opting into maintainsFileIdentity are that the backend needs to implement getName itself:

https://github.com/emscripten-core/emscripten/blob/340aa0f451c1680c3a0dfbe65a42651c8d187307/system/lib/wasmfs/file.h#L254-L263

It sounds like maybe we have backends that aren't doing this correctly? If so, it would be better to fix the backends to make sure the implementation is consistent with the documented intent.

tlively avatar Mar 17 '25 22:03 tlively

It sounds like maybe we have backends that aren't doing this correctly? If so, it would be better to fix the backends to make sure the implementation is consistent with the documented intent.

Yeah memory backend does this:

std::string MemoryDirectory::getName(std::shared_ptr<File> file) {
  auto it =
    std::find_if(entries.begin(), entries.end(), [&](const auto& entry) {
      return entry.child == file;
    });
  if (it != entries.end()) {
    return it->name;
  }
  return "";
}

But the entries don't seem to contain the file that is requested in these paths, the mounted folder itself I assume?

guusw avatar Mar 21 '25 06:03 guusw