emscripten
emscripten copied to clipboard
Fix retrieval of mounted directory names
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/
Can you add a test for this? That might also help me understand the problem we are solving here.
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
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?
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.
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?