Skip to content

Commit

Permalink
[FS] Ensure parent node is always updated in rename(), regardless of …
Browse files Browse the repository at this point in the history
…backend (#21964)

Doing the update in the core logic avoids each backend needing to do it,
and avoids the risk of a backend forgetting (as was the case with NODEFS,
which this fixes).
  • Loading branch information
Siobhan Bamber committed May 22, 2024
1 parent ed95123 commit b01e901
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,9 @@ FS.staticInit();` +
// do the underlying fs rename
try {
old_dir.node_ops.rename(old_node, new_dir, new_name);
// update old node (we do this here to avoid each backend
// needing to)
old_node.parent = new_dir;
} catch (e) {
throw e;
} finally {
Expand Down
1 change: 0 additions & 1 deletion src/library_memfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ addToLibrary({
old_node.name = new_name;
new_dir.contents[new_name] = old_node;
new_dir.timestamp = old_node.parent.timestamp;
old_node.parent = new_dir;
},
unlink(parent, name) {
delete parent.contents[name];
Expand Down
1 change: 0 additions & 1 deletion src/library_proxyfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ addToLibrary({
try {
oldNode.mount.opts.fs.rename(oldPath, newPath);
oldNode.name = newName;
oldNode.parent = newDir;
} catch(e) {
if (!e.code) throw e;
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
Expand Down

0 comments on commit b01e901

Please sign in to comment.