Skip to content

WasmFS: Open and close files in the JS API _wasmfs_write_file #19397

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

Merged
merged 1 commit into from
May 19, 2023

Conversation

kripken
Copy link
Member

@kripken kripken commented May 19, 2023

The memory backend appears to allow lockedFile.write without .open first,
but other backends like Node do not. In general, it seems correct to open
the file before writing and close it after, and the read JS API call does so, so this
fixes the write one.

This is necessary for NODERAWFS support and will be tested in that PR.

@kripken kripken requested a review from tlively May 19, 2023 16:34
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Seems reasonable. There are definitely situations where an open might fail but a write would not, for example for files that have been unlinked already (for backends that support that) or perhaps for special files like pipes that don't expect to be opened at all, but in those cases I would expect users to use lower level APIs rather than this all-in-one high level API.

@kripken kripken merged commit 7e8b11c into main May 19, 2023
@kripken kripken deleted the wasmfs.js.write.oc branch May 19, 2023 18:21
kripken added a commit that referenced this pull request May 22, 2023
This PR makes the NODERAWFS flag make the root directory be
created using the Node backend. That may not be 100% of what we
need for NODERAWFS but it gets a significant amount of tests
passing.

To do that, add a hook that backends can use to override creation of
the root directory. Then NODERAWFS support basically is just to link
in a tiny library that overrides that hook.

This adds a new test, test_noderawfs_wasmfs which verifies we write
files out to the normal filesystem. Also, enable test_freetype, which
now passes; previously it failed during a configure step (specifically,
configure tried to write the size of an integer to a file... before this
PR, the file was empty and it defined integer size as the empty string).
So test_freetype both verifies NODERAWFS writes, and also it uses
files internally (to read font files etc.) which seems useful to enable.

Also, this is tested in test_fs_writeFile_rawfs. That test does
FS.writeFile with NODERAWFS enabled. It passed before, because
enabling NODERAWFS did nothing... for WasmFS the test really just
worked on the MemoryFile backend, since it doesn't create a Node
backend. With this PR, the test properly uses Node files, and passes
(thanks to #19397 and #19396).

Note: other.test_unistd_fstatfs_wasmfs was removed from CI because
it was unnecessary - all other tests run anyhow. We only need to add
select wasmfs tests because that mode does not run in full already.
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.

2 participants