Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WASMFS FS.createPath match the FS version behavior on EEXIST #23603

Merged
merged 4 commits into from
Feb 10, 2025

Conversation

JoeOsborn
Copy link
Contributor

Fixes #23602.

If the file packager tries to add content to *an existing path* in the
filesystem (e.g., if the filesystem already has some directories, OPFS
content, loading multiple package, etc), the different behavior of
createPath causes an exception on WASMFS and no exception on JS FS.
@JoeOsborn JoeOsborn force-pushed the fix-wasmfs-createpath branch from 83a2bc9 to af57bd6 Compare February 5, 2025 23:49
@JoeOsborn
Copy link
Contributor Author

I've added a test. The trigger I noticed is when you load multiple packages which overlap at all in their target paths, or when you load a package into a filesystem that already has content (even if it doesn't overlap with the actual package contents).

createPath was also just less pleasant to use in WASMFS compared to JS FS due to this difference.

test/test_emscripten_overlapped_package.c Outdated Show resolved Hide resolved
test/test_browser.py Show resolved Hide resolved
test/test_browser.py Outdated Show resolved Hide resolved
@JoeOsborn JoeOsborn force-pushed the fix-wasmfs-createpath branch from bc18c55 to 3e2760e Compare February 6, 2025 16:59
@JoeOsborn
Copy link
Contributor Author

So I didn't add a test specifically for createPath, because I do like that the current test exercises the separate file packager and createPath isn't documented to succeed or fail with respect to whether the paths exist already. I can add a separate JS test if you think it's important.

@JoeOsborn
Copy link
Contributor Author

The fs_js_api tests seem a bit broken. They don't work in strict mode (and changing the octal literals to 0o777 causes breakage in other conditions) or WASM64, and there's a memory leak in wasmfs found during read. Do you still want me to add a WASMFS condition to test_fs_js_api?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 6, 2025

The fs_js_api tests seem a bit broken. They don't work in strict mode (and changing the octal literals to 0o777 causes breakage in other conditions) or WASM64, and there's a memory leak in wasmfs found during read. Do you still want me to add a WASMFS condition to test_fs_js_api?

My understanding is the test_fs_js_api was added precisely so that we could test the wasmfs versions of the APIs, so I think we should fix them if they are broken, yes. I'm a little confused as to why its not marked as @also_with_wasmfs but I guess its run explicitly as wasmfs.test_fs_js_api in circleci.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't mean to include this.

@JoeOsborn JoeOsborn force-pushed the fix-wasmfs-createpath branch from f079bba to f07e4ac Compare February 6, 2025 23:19
@kripken kripken merged commit 917568d into emscripten-core:main Feb 10, 2025
29 checks passed
@JoeOsborn
Copy link
Contributor Author

So I tried to move my packager test into test_other, but it actually only breaks in browser (node has its own filesystem stuff used by the file_packager scripts). Is there a good way to write a test_other test that still runs in a browser environment? Currently my packager test is still in test_core

@sbc100
Copy link
Collaborator

sbc100 commented Feb 10, 2025

So I tried to move my packager test into test_other, but it actually only breaks in browser (node has its own filesystem stuff used by the file_packager scripts). Is there a good way to write a test_other test that still runs in a browser environment? Currently my packager test is still in test_core

No, the point of test_other is that doesn't run in the browser.

@@ -111,7 +111,11 @@ FS.init();
if (!wasmFSPreloadingFlushed) {
wasmFSPreloadedDirs.push({parentPath: parent, childName: part});
} else {
FS.mkdir(current);
try {
FS.mkdir(current);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm actually little confused by this fix. I tried running wasmfs.test_fs_js_api and it passed both with or without this change.

Looking into it it looks the repeated calls to FS.mkdir here always seem to succeed. I modified the code here to add some extra debugging and I see:


mkdir /home/nested1
0
mkdir /home/nested2
0

I'm a little confused how you were hitting an error here? I must be missing something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm even stranger, browser.test_emscripten_overlapped_package seem to pass both before and after this test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I wasn't running browser.test_emscripten_overlapped_package_wasmfs.. that one does fail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I found the issue with test_fs_js_api: #23645

sbc100 added a commit to sbc100/emscripten that referenced this pull request Feb 10, 2025
sbc100 added a commit that referenced this pull request Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WASMFS FS.createPath doesn't ignore EEXIST
3 participants