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

When opening broken symlink with O_CREAT, create file at target #23002

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Nov 25, 2024

If we open a broken symlink with O_CREAT we should create a new file as the target of the symlink.
This resolves #23001.

To fix the problem, I added an extra handleBrokenLink option to lookupPath. When this option is passed, if the input path is a broken symlink, instead of raising EEXIST, it returns { path: theTarget, node: undefined}. Then in open we update path based on the returned path, so if the node doesn't exist we attempt create it at the resolved target path of the symlink rather than trying to create it on the source of the symlink which raises EEXIST again.

  • Add a test

@hoodmane hoodmane marked this pull request as draft November 25, 2024 15:18
@hoodmane

This comment was marked as resolved.

@hoodmane hoodmane changed the title When opening broken symlink with O_CREAT, replace it When opening broken symlink with O_CREAT, create file at target Nov 25, 2024
@hoodmane hoodmane marked this pull request as ready for review November 25, 2024 19:20
Comment on lines 223 to 226
if (!current.node_ops.readlink) {
throw new FS.ErrnoError({{{ cDefs.ENOSYS }}});
}
var link = current.node_ops.readlink(current);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before this change, FS.readlink calls lookupPath again which repeats exactly the same work we've done up to this point in this function except with opts.follow false. Rather than doing that, we already have the node here so I figure it's better just to call node_ops.readlink.

test/unistd/write_broken_link.c Outdated Show resolved Hide resolved
test/unistd/write_broken_link.c Outdated Show resolved Hide resolved
src/library_fs.js Outdated Show resolved Hide resolved
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.

Opening broken symlink with O_CREAT returns EEXIST unlike linux
2 participants