Skip to content

Commit 8da8cb1

Browse files
authored
Make readlink system call not resolve the link (#23000)
Readlink in linux does not resolve the link, it returns the exact link contents. Resolves #22999.
1 parent e191834 commit 8da8cb1

File tree

2 files changed

+1
-17
lines changed

2 files changed

+1
-17
lines changed

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ FS.staticInit();
902902
if (!link.node_ops.readlink) {
903903
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
904904
}
905-
return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link));
905+
return link.node_ops.readlink(link);
906906
},
907907
stat(path, dontFollow) {
908908
var lookup = FS.lookupPath(path, { follow: !dontFollow });

test/unistd/links.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,7 @@ void test_reading_existing_symlinks() {
8181
continue;
8282
}
8383

84-
// WASMFS behaves the same as Linux (and as best as I can tell, the spec),
85-
// seeing the symlink as a string. The old JS FS instead normalizes it and
86-
// returns something modified.
87-
// The same happens in the assertions below.
88-
#if !defined(__EMSCRIPTEN__) || defined(WASMFS)
8984
assert(strcmp(buffer, "../test/../there!") == 0);
90-
#else
91-
assert(strcmp(buffer, "/there!") == 0);
92-
#endif
9385
assert(strlen(buffer) == rtn);
9486
errno = 0;
9587
}
@@ -111,11 +103,7 @@ void test_creating_symlink() {
111103
char buffer[256] = {0};
112104
rtn = readlink("directory/link", buffer, 256);
113105
assert(errno == 0);
114-
#if !defined(__EMSCRIPTEN__) || defined(WASMFS)
115106
assert(strcmp(buffer, "new-nonexistent-path") == 0);
116-
#else
117-
assert(strcmp(buffer, "/working/directory/new-nonexistent-path") == 0);
118-
#endif
119107
assert(strlen(buffer) == rtn);
120108
errno = 0;
121109
}
@@ -127,11 +115,7 @@ void test_reading_shortened_symlink() {
127115
int rtn = readlink("link", buffer, 4);
128116
assert(errno == 0);
129117
assert(rtn == 4);
130-
#if !defined(__EMSCRIPTEN__) || defined(WASMFS)
131118
assert(strcmp(buffer, "../t**nexistent-path") == 0);
132-
#else
133-
assert(strcmp(buffer, "/the**ng/directory/new-nonexistent-path") == 0);
134-
#endif
135119
errno = 0;
136120
}
137121

0 commit comments

Comments
 (0)