Skip to content

[WasmFS] Update host paths of renamed files in the Node backend - #27849

Open
typedrat wants to merge 1 commit into
emscripten-core:mainfrom
typedrat:typedrat/wasmfs-node-rename
Open

typedrat wants to merge 1 commit into
emscripten-core:mainfrom
typedrat:typedrat/wasmfs-node-rename

Conversation

@typedrat

@typedrat typedrat commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

NodeDirectory::insertMove renamed the file on the host but left the host path cached in the moved File, and in everything already looked up below a moved directory, pointing at the old name. Later operations then failed, or read and wrote a different file created under the old name.

insertMove now rewrites the cached host path of the moved file and of every loaded file below it, which it finds through a new protected Directory::getLoadedChildren(). It holds their locks, parents first, across the host's rename, so no operation sees a path change under it. It also stops casting a moved symlink to a directory, and returns EBUSY for a mount point of another backend (as Linux and the JS file system's FS.rename do) instead of treating it as a Node file.

Locking and #27684: the new locks are only taken downward, after renameat's ancestor walk, in the same parent-before-child order lookups use. So this neither depends on #27685 nor conflicts with it.

Test: other.test_wasmfs_rename (memory, NODEFS and NODERAWFS) renames a file and reuses its old name, renames a directory with an open file, looked-up files and a symlink inside, moves a symlink, and checks EBUSY for a mount point. The Node variants fail on main and pass with this change. The test is single-threaded, so it doesn't exercise the locking.

Fixes: #27824

`NodeDirectory::insertMove` renamed the file on the host but left the host
path cached in the moved file, and in everything already looked up below a
moved directory, pointing at the old name. Later operations then used the
old path: they failed, or reached a different file created under the old
name.

Rewrite the cached host path of the moved file and of every loaded file
below it, holding their locks (each before its children) across the host's
rename. Moving a symlink no longer casts it to a directory, and moving a
mount point of another backend now fails with EBUSY, as on Linux and in the
JS file system, instead of being treated as a Node file.

Fixes: emscripten-core#27824

This branch has not been deployed

No deployments
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 Node backend: after rename(), a file (or anything already looked up under a renamed directory) still refers to its old host path

1 participant