Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/lib/libfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ FS.staticInit();

if (parts[i] === '..') {
current_path = PATH.dirname(current_path);
current = current.parent;
if (FS.isRoot(current)) {
path = current_path + '/' + parts.slice(i + 1).join('/');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the current node is the root node can we just assume current path is / here and do path = '/' + parts.slice(i + 1).join('/')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because FS.isRoot() returns true if it's the root of a mount. So in the test, because we mounted NODEFS at /working, FS.isRoot() will return true when processing the .. in the path "/working/../other".

continue linkloop;
} else {
current = current.parent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If parts[i] === '..' and the current not is the FS root shouldn't we be failing? (Since there is no parent of the root?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not consistent with linux's stat. If a .. is seen at the root, it is ignored:

$ stat /../lib
  File: /../lib -> usr/lib
  Size: 7         	Blocks: 0          IO Block: 4096   symbolic link

}
continue;
}

Expand Down
15 changes: 15 additions & 0 deletions test/other/test_resolve_mountpoint_parent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <emscripten.h>
#include "assert.h"

int main(int argc, char **argv) {
EM_ASM({
FS.mkdir('/working');
FS.mkdir('/other');
FS.mount(NODEFS, { root: '.' }, '/working');
});
struct stat statBuf;
assert(stat("/working/../other", &statBuf) == 0);
}
Empty file.
5 changes: 5 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8164,6 +8164,11 @@ def test_realpath_2(self):
create_file('Folder/testfile.txt', '')
self.do_other_test('test_realpath_2.c', emcc_args=['--embed-file', 'testfile.txt', '--embed-file', 'Folder'])

@requires_node
@also_with_wasmfs
def test_resolve_mountpoint_parent(self):
self.do_other_test('test_resolve_mountpoint_parent.c', emcc_args=['-sFORCE_FILESYSTEM', '-lnodefs.js'])

@with_env_modify({'EMCC_LOGGING': '0'}) # this test assumes no emcc output
def test_no_warnings(self):
# build once before to make sure system libs etc. exist
Expand Down
Loading