Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a5fe8cd
readlink method returns grand parent when parent path equals current …
mho22 Apr 23, 2024
7d672ac
Merge branch 'emscripten-core:main' into patch-1
mho22 Apr 25, 2024
5941467
Improved readlink behavior to accept absolute paths
Apr 25, 2024
ca48b26
Improved readlink behavior to accept absolute paths
Apr 25, 2024
a39210b
Improved readlink behavior to understand absolute paths
Apr 27, 2024
521a95e
Merge branch 'main' into patch-1
mho22 Apr 30, 2024
122ff6a
Merge branch 'main' into patch-1
mho22 May 2, 2024
26a514a
Merge branch 'main' into patch-1
mho22 May 2, 2024
5300efc
Merge branch 'main' into patch-1
mho22 May 3, 2024
38c0631
Cleared readlink relative path manipulation
mho22 May 4, 2024
5abe4b7
Merge branch 'patch-1' of github.com:mho22/emscripten into patch-1
mho22 May 4, 2024
fdf4a4c
Improved readlink behavior to understand absolute paths
mho22 May 5, 2024
bd746f1
Improved readlink behavior to understand absolute paths
mho22 May 5, 2024
94b6d6d
Improved readlink behavior to understand absolute paths
mho22 May 5, 2024
8eefae8
Improved readlink behavior to understand absolute paths
mho22 May 6, 2024
d51fe58
Revert resolving outside VFS absolute symlinks
mho22 May 6, 2024
445b52a
Revert resolving outside VFS absolute symlinks
mho22 May 7, 2024
271c523
Revert resolving outside VFS absolute symlinks
mho22 May 7, 2024
82298ce
Revert resolving outside VFS absolute symlinks
mho22 May 7, 2024
a340985
Revert resolving outside VFS absolute symlinks
mho22 May 8, 2024
faaa6f7
Revert resolving outside VFS absolute symlinks
mho22 May 8, 2024
4a81b4b
Merge branch 'main' into patch-1
mho22 May 8, 2024
0ef6e4f
Revert resolving outside VFS absolute symlinks
mho22 May 8, 2024
bf23b63
Merge branch 'patch-1' of github.com:mho22/emscripten into patch-1
mho22 May 8, 2024
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
27 changes: 16 additions & 11 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ to browse the changes between the tags.

See docs/process.md for more on how version tagging works.

3.1.61 - 05/08/24
-----------------
- Under nodefs, symbolic links to files outside of mount locations no longer work.
This reverts the previous behaviour added in #3277. (#21805)

3.1.60 (in development)
-----------------------
- The `EXPORTED_FUNCTIONS` list can now include JS library symbols even if they
Expand Down Expand Up @@ -139,17 +144,17 @@ See docs/process.md for more on how version tagging works.
the top of the JS file. This is useful as it allows things like `{{{
POINTER_SIZE }}}` and `{{{ makeGetValue(..) }}}` to be used in pre/post JS
files, just like they can be in JS library files. (#21227)
- Added concept of contrib ports which are ports contributed by the wider
community and supported on a "best effort" basis. See
`tools/ports/contrib/README.md` for details.A first contrib port is
available via `--use-port=contrib.glfw3`: an emscripten port of glfw written
in C++ with many features like support for multiple windows. (#21244 and
- Added concept of contrib ports which are ports contributed by the wider
community and supported on a "best effort" basis. See
`tools/ports/contrib/README.md` for details.A first contrib port is
available via `--use-port=contrib.glfw3`: an emscripten port of glfw written
in C++ with many features like support for multiple windows. (#21244 and
#21276)
- Added concept of external ports which live outside emscripten and are
loaded on demand using the syntax `--use-port=/path/to/my_port.py` (#21316)
- `embuilder` can now build ports with options as well as external ports using
the same syntax introduced with `--use-port`
(ex: `embuilder sdl2_image:formats=png,jpg`) (#21345)
(ex: `embuilder sdl2_image:formats=png,jpg`) (#21345)
- Allow comments in response files. Any line starting with `#` is now ignored.
This is useful when listing exported symbols. (#21330)

Expand Down Expand Up @@ -195,7 +200,7 @@ See docs/process.md for more on how version tagging works.
is intending to target them today. (#20924)
- C++ objects passed into embind's val via constructors, methods, and call
function will not be automatically destroyed after the function call. This
makes the behavior consistent for invocations.
makes the behavior consistent for invocations.
- The `SUPPORT_ERRNO` setting is now deprecated as it only controlled setting
errno from JS library functions and emscripten no longer requires this.
(#21074)
Expand Down Expand Up @@ -267,7 +272,7 @@ See docs/process.md for more on how version tagging works.
- The `glfwSetWindowSize` function no longer switches to fullscreen when the
width/height provided as parameters match the screen size. This behavior
now matches the behavior of SDL and glut. In order to switch to fullscreen,
the client code should invoke `Module.requestFullscreen(...)` from a user
the client code should invoke `Module.requestFullscreen(...)` from a user
triggered event otherwise the browser raises an error. (#20600)

3.1.48 - 11/05/23
Expand Down Expand Up @@ -468,7 +473,7 @@ See docs/process.md for more on how version tagging works.
- stringToUTF8Array
- stringToUTF8
- lengthBytesUTF8

If you use any of these functions in your JS code you will now need to include
them explicitly in one of the following ways:
- Add them to a `__deps` entry in your JS library file (with leading $)
Expand Down Expand Up @@ -503,7 +508,7 @@ See docs/process.md for more on how version tagging works.
- When targeting node, and using `-sMODULARIZE`, we no longer internally catch
unhandled promise rejections or exit status code. That is to say the,
`NODEJS_CATCH_REJECTION` and `NODEJS_CATCH_EXIT` are no longer compatible
with `-sMODULARIZE`.
with `-sMODULARIZE`.

3.1.33 - 03/08/23
-----------------
Expand All @@ -524,7 +529,7 @@ See docs/process.md for more on how version tagging works.
(#18861)
- The `emscripten_proxy_async_with_callback` API was replaced with a simpler
`emscripten_proxy_callback` API that takes a second callback to be called if
the worker thread dies before completing the proxied work.
the worker thread dies before completing the proxied work.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you revert all these unralated changes to the ChangeLog where newlines are removed?

BTW, the way I setup my editor is to (1) show trailing whitespace and (2) have a shortcut to strip it all, but not to have it do this automatically.. otherwise you end up with changes like this.

Copy link
Contributor Author

@mho22 mho22 May 8, 2024

Choose a reason for hiding this comment

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

Thanks for the insights and sorry for the inconvenience.

I indeed had these three lines in my vscode/settings.json file enabled :

"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,

I should be more careful.


3.1.32 - 02/17/23
-----------------
Expand Down
4 changes: 1 addition & 3 deletions src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ addToLibrary({
readlink(node) {
var path = NODEFS.realPath(node);
try {
path = fs.readlinkSync(path);
path = nodePath.relative(nodePath.resolve(node.mount.opts.root), path);
return path;
return fs.readlinkSync(path);
} catch (e) {
if (!e.code) throw e;
// node under windows can return code 'UNKNOWN' here:
Expand Down
182 changes: 141 additions & 41 deletions test/unistd/links.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,70 @@
#include <emscripten.h>
#endif

void setup() {
int rtn = mkdir("working", 0777);
assert(rtn == 0);
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
#endif
rtn = chdir("working");
void makedir(char *dir) {
int rtn = mkdir(dir, 0777);
assert(rtn == 0);
symlink("../test/../there!", "link");
int fd = open("file", O_RDWR | O_CREAT, 0777);
}

void makefile(char *file, char *content) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use const char * for both args here and args below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it!

int fd = open(file, O_RDWR | O_CREAT, 0777);
assert(fd >= 0);
rtn = write(fd, "test", 5);
assert(rtn == 5);
int rtn = write(fd, content, strlen(content));
assert(rtn == strlen(content));
close(fd);
rtn = mkdir("folder", 0777);
}

void makelink(char *link, char *path) {
int rtn = symlink(link, path);
assert(rtn == 0);
}

int main() {
setup();
void changedir(char *dir) {
int rtn = chdir(dir);
assert(rtn == 0);
}

char* files[] = {"link", "file", "folder"};
char buffer[256] = {0};
int ret;
void setup() {
makedir("working");
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
#endif
changedir("working");
makelink("../test/../there!", "link");
makefile("file", "test");
makedir("directory");
makedir("directory/subdirectory");
makefile("directory/subdirectory/file", "Subdirectory");

makedir("relative");
makedir("relative/subrelative");
makefile("relative/file", "Relative");
makefile("relative/subrelative/file", "Subrelative");
makelink("../relative/file", "directory/relative");
makelink("../../relative/subrelative/file", "directory/subdirectory/subrelative");
makelink("directory/subdirectory/file", "subdirectoryrelative");

makedir("absolute");
makedir("absolute/subabsolute");
makefile("absolute/file", "Absolute");
makefile("absolute/subabsolute/file", "Subabsolute");
makelink("/working/absolute/file", "/working/directory/absolute");
makelink("/working/absolute/subabsolute/file", "/working/directory/subdirectory/subabsolute");
makelink("/working/directory/subdirectory/file", "/working/subdirectoryabsolute");
}

void test_reading_existing_symlinks() {
char* files[] = {"link", "file", "directory"};

for (int i = 0; i < sizeof files / sizeof files[0]; i++) {
printf("readlink(%s)\n", files[i]);
ret = readlink(files[i], buffer, 256);
printf("errno: %s\n", strerror(errno));
if (ret < 0) {
printf("not a link\n\n");
char buffer[256] = {0};
int rtn = readlink(files[i], buffer, 256);
printf("readlink: '%s'\n", files[i]);
printf("errno: %s\n\n", strerror(errno));
if (rtn < 0) {
continue;
}

// WASMFS behaves the same as Linux (and as best as I can tell, the spec),
// seeing the symlink as a string. The old JS FS instead normalizes it and
// returns something modified.
Expand All @@ -59,56 +90,125 @@ int main() {
#else
assert(strcmp(buffer, "/there!") == 0);
#endif
assert(strlen(buffer) == ret);
assert(strlen(buffer) == rtn);
errno = 0;
printf("\n");
}
}

printf("symlink/overwrite\n");
ret = symlink("new-nonexistent-path", "link");
assert(ret == -1);
void test_overwriting_symlink() {
int rtn = symlink("new-nonexistent-path", "link");
assert(rtn == -1);
assert(errno == EEXIST);
errno = 0;
}

printf("\nsymlink/normal\n");
ret = symlink("new-nonexistent-path", "folder/link");
assert(ret == 0);
void test_creating_symlink() {
int rtn = symlink("new-nonexistent-path", "directory/link");
assert(rtn == 0);
assert(errno == 0);
errno = 0;

printf("\nreadlink(created link)\n");
ret = readlink("folder/link", buffer, 256);
char buffer[256] = {0};
rtn = readlink("directory/link", buffer, 256);
assert(errno == 0);
#if !defined(__EMSCRIPTEN__) || defined(WASMFS)
assert(strcmp(buffer, "new-nonexistent-path") == 0);
#else
assert(strcmp(buffer, "/working/folder/new-nonexistent-path") == 0);
assert(strcmp(buffer, "/working/directory/new-nonexistent-path") == 0);
#endif
assert(strlen(buffer) == ret);
assert(strlen(buffer) == rtn);
errno = 0;
}

void test_reading_shortened_symlink() {
char buffer[256] = {0};
readlink("directory/link", buffer, 256);
buffer[0] = buffer[1] = buffer[2] = buffer[3] = buffer[4] = buffer[5] = '*';
printf("\nreadlink(short buffer)\n");
ret = readlink("link", buffer, 4);
int rtn = readlink("link", buffer, 4);
assert(errno == 0);
assert(ret == 4);
assert(rtn == 4);
#if !defined(__EMSCRIPTEN__) || defined(WASMFS)
assert(strcmp(buffer, "../t**nexistent-path") == 0);
#else
assert(strcmp(buffer, "/the**ng/folder/new-nonexistent-path") == 0);
assert(strcmp(buffer, "/the**ng/directory/new-nonexistent-path") == 0);
#endif
errno = 0;
}

void test_noticing_loop_in_symlink() {
// FS.lookupPath should notice the symlink loop and return ELOOP, not go into
// an infinite recurse.
//
// This test doesn't work in wasmfs -- probably because access sees the
// symlink and returns true without bothering to chase the symlink
symlink("./linkX/inside", "./linkX");
ret = access("linkX", F_OK);
assert(ret == -1);
symlink("./loop-link/inside", "./loop-link");
int rtn = access("loop-link", F_OK);
assert(rtn == -1);
assert(errno == ELOOP);
errno = 0;
}


void test_relative_path_symlinks() {
char* parents[] = {
"/working/directory/",
"/working/directory/subdirectory/",
"/working/"
};

char* links[] = {
"relative",
"subrelative",
"subdirectoryrelative",
};

for (int i = 0; i < sizeof links / sizeof links[0]; i++) {
int rtn = chdir(parents[i]);
assert(rtn == 0);
char symlink[256] = {0};
strcat(strcpy(symlink, parents[i]), links[i]);
printf("symlink: '%s'\n", symlink);
char buf[256] = {0};
rtn = readlink(links[i], buf, 256);
FILE *fd = fopen(buf, "r");
assert(fd);
char buffer[13] = {0};
rtn = fread(buffer, 1, 13, fd);
assert(rtn <= 13);
printf("buffer: '%s'\n\n", buffer);
fclose(fd);
}
}

void test_absolute_path_symlinks() {
char* links[] = {
"/working/directory/absolute",
"/working/directory/subdirectory/subabsolute",
"/working/subdirectoryabsolute"
};

for (int i = 0; i < sizeof links / sizeof links[0]; i++) {
printf("symlink: '%s'\n", links[i]);
char buf[256] = {0};
readlink(links[i], buf, 256);
FILE *fd = fopen(buf, "r");
assert(fd);
char buffer[13] = {0};
int rtn = fread(buffer, 1, 13, fd);
assert(rtn <= 13);
printf("buffer: '%s'\n\n", buffer);
fclose(fd);
}
}

int main() {
setup();
test_reading_existing_symlinks();
test_overwriting_symlink();
test_creating_symlink();
test_reading_shortened_symlink();
test_noticing_loop_in_symlink();
test_relative_path_symlinks();
test_absolute_path_symlinks();
return 0;
}
26 changes: 17 additions & 9 deletions test/unistd/links.out
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
readlink(link)
readlink: 'link'
errno: No error information

readlink(file)
readlink: 'file'
errno: Invalid argument
not a link

readlink(folder)
readlink: 'directory'
errno: Invalid argument
not a link

symlink/overwrite
symlink: '/working/directory/relative'
buffer: 'Relative'

symlink/normal
symlink: '/working/directory/subdirectory/subrelative'
buffer: 'Subrelative'

readlink(created link)
symlink: '/working/subdirectoryrelative'
buffer: 'Subdirectory'

readlink(short buffer)
symlink: '/working/directory/absolute'
buffer: 'Absolute'

symlink: '/working/directory/subdirectory/subabsolute'
buffer: 'Subabsolute'

symlink: '/working/subdirectoryabsolute'
buffer: 'Subdirectory'
Loading