-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Fix WriteUTF8FileAtomic to preserve symlinks #10908
Conversation
@check-spelling-bot ReportUnrecognized words, please review:
Previously acknowledged words that are now absentDECDLD SPACEBAR UnregisterTo accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the [email protected]:Don-Vito/terminal.git repository
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbageIf it relates to a ... well-formed patternSee if there's a pattern that would match it. If not, try writing one and adding it to a Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines. Note that patterns can't match multiline strings. binary-ish stringPlease add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
@eryksun What's the default value of |
@Don-Vito |
It's the other way around. It's true when there's a non-zero error value and otherwise false: |
Ah thanks! |
You are right 😄 and this is exactly what I meant when saying that initial error code is 0 (success). Which means that if the symlink was not invoked then the value remains success, and thus if(ec) returns false. I just didn't mention is that this conversion done by bool() operator. And of course I also tested all these scenarios after each code change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm v. cool with this; thanks for doing it! 😄
@msftbot merge this in 5 minutes |
Hello @DHowett! Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:
If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you". |
Also? Welcome back! 👏🏻 |
Thanks! :) Hope to finally get some vacation soon (aka best time for coding), so I am warming up :) |
WriteUTF8FileAtomic overrides the content of the file "atomically" by creating a temp file and then renaming it to the original path. The problem arises when the original path is symbolic link, as the link itself gets overridden by a file (rather than the link target). This PR introduces a special handling of the symlinks: if the path as a symlink we resolve the path and use: 1. target's directory to create a temp-file in 2. target itself to be replaced with the tempfile. Symlink resolution is problematic when the target path does not exist, as there is no good utility that resolves such link (canonical() fails). In this corner case we skip the "atomic" approach of renaming the file and write the link target directly. Closes #10787
🎉 Handy links: |
🎉 Handy links: |
WriteUTF8FileAtomic overrides the content of the file "atomically"
by creating a temp file and then renaming it to the original path.
The problem arises when the original path is symbolic link,
as the link itself gets overridden by a file (rather than the link target).
This PR introduces a special handling of the symlinks:
if the path as a symlink we resolve the path and use:
Symlink resolution is problematic when the target path does not exist,
as there is no good utility that resolves such link (canonical() fails).
In this corner case we skip the "atomic" approach of renaming the file
and write the link target directly.
Closes #10787