Skip to content

Commit 66fa4f7

Browse files
committed
FIX resolvePath handling of .. up from fs root
node.parent doesn't actually give us the parent if the node is a FS root. In that case, instead of using `node.parent` we should start over from the beginning. Resolves #23983.
1 parent 53b38d0 commit 66fa4f7

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/lib/libfs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ FS.staticInit();
199199

200200
if (parts[i] === '..') {
201201
current_path = PATH.dirname(current_path);
202-
current = current.parent;
202+
if (FS.isRoot(current)) {
203+
path = current_path + '/' + parts.slice(i + 1).join('/');
204+
continue linkloop;
205+
} else {
206+
current = current.parent;
207+
}
203208
continue;
204209
}
205210

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <sys/types.h>
2+
#include <sys/stat.h>
3+
#include <unistd.h>
4+
#include <emscripten.h>
5+
#include "assert.h"
6+
7+
int main(int argc, char **argv) {
8+
EM_ASM({
9+
FS.mkdir('/working');
10+
FS.mkdir('/other');
11+
FS.mount(NODEFS, { root: '.' }, '/working');
12+
});
13+
struct stat statBuf;
14+
assert(stat("/working/../other", &statBuf) == 0);
15+
}

test/other/test_resolve_mountpoint_parent.out

Whitespace-only changes.

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8164,6 +8164,11 @@ def test_realpath_2(self):
81648164
create_file('Folder/testfile.txt', '')
81658165
self.do_other_test('test_realpath_2.c', emcc_args=['--embed-file', 'testfile.txt', '--embed-file', 'Folder'])
81668166

8167+
@requires_node
8168+
@also_with_wasmfs
8169+
def test_resolve_mountpoint_parent(self):
8170+
self.do_other_test('test_resolve_mountpoint_parent.c', emcc_args=['-sFORCE_FILESYSTEM', '-lnodefs.js'])
8171+
81678172
@with_env_modify({'EMCC_LOGGING': '0'}) # this test assumes no emcc output
81688173
def test_no_warnings(self):
81698174
# build once before to make sure system libs etc. exist

0 commit comments

Comments
 (0)