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

Ensure parent node is always updated in rename(), regardless of fs implementation #21964

Merged
3 changes: 3 additions & 0 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ FS.staticInit();` +
} catch (e) {
throw e;
} finally {
// update old node (called here to ensure consistency
// across fs implementations)
old_node.parent = new_dir;
Copy link
Member

@kripken kripken May 21, 2024

Choose a reason for hiding this comment

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

Reading this again, I don't think we want this to run if an exception happens. Not running it in that case would match the previous behavior - the old places that set the parent were only reached if nothing was thrown. So let's move this to right after the finally. edit: unless that doesn't work in your case for some reason?

For the comment, how about update old node (we do this here to avoid each backend needing to) - ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reading this again, I don't think we want this to run if an exception happens. Not running it in that case would match the previous behavior - the old places that set the parent were only reached if nothing was thrown. So let's move this to right after the finally. edit: unless that doesn't work in your case for some reason?

Nice catch :D I agree that makes sense and everything still worked as expected for our use case, I updated in 631a8bf.

For the comment, how about update old node (we do this here to avoid each backend needing to) - ?

I think that update has a lot more clarity! I applied that change in b555a45.

// add the node back to the hash (in case node_ops.rename
// changed its name)
FS.hashAddNode(old_node);
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