Skip to content

Commit d75b1be

Browse files
committed
Make readlink system call not resolve the link
Readlink in linux does not resolve the link, it returns the exact link contents.
1 parent b3edd4c commit d75b1be

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/library_fs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ FS.staticInit();
895895
}
896896
#endif
897897
},
898-
readlink(path) {
898+
readlink(path, opts = {}) {
899899
var lookup = FS.lookupPath(path);
900900
var link = lookup.node;
901901
if (!link) {
@@ -904,7 +904,11 @@ FS.staticInit();
904904
if (!link.node_ops.readlink) {
905905
throw new FS.ErrnoError({{{ cDefs.EINVAL }}});
906906
}
907-
return PATH_FS.resolve(FS.getPath(link.parent), link.node_ops.readlink(link));
907+
const target = link.node_ops.readlink(link);
908+
if (opts.noResolve) {
909+
return target;
910+
}
911+
return PATH_FS.resolve(FS.getPath(link.parent), target);
908912
},
909913
stat(path, dontFollow) {
910914
var lookup = FS.lookupPath(path, { follow: !dontFollow });

src/library_syscall.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ var SyscallsLibrary = {
919919
path = SYSCALLS.getStr(path);
920920
path = SYSCALLS.calculateAt(dirfd, path);
921921
if (bufsize <= 0) return -{{{ cDefs.EINVAL }}};
922-
var ret = FS.readlink(path);
922+
var ret = FS.readlink(path, {noResolve: true});
923923

924924
var len = Math.min(bufsize, lengthBytesUTF8(ret));
925925
var endChar = HEAP8[buf+len];

0 commit comments

Comments
 (0)