fix: support symlinks in atomic file write methods#3324
fix: support symlinks in atomic file write methods#3324jarhodes314 merged 1 commit intothin-edge:mainfrom
Conversation
There was a problem hiding this comment.
It appears permissions are ignored (/essentially don't exist) for symlinks on Linux, so I have updated this to use read_link, which will read a broken symlink as well as a working one. As far as I understand, this won't hold true on BSD or MacOS, but we aren't targeting those platforms for production, and it's also an extreme edge case that you'd have to go to some effort to find yourself in.
My original (incorrect) thoughts:
I believe this would still clobber the symlink in the case where:
- we have write access to the directory containing the symlink
- we don't have read access to the symlink itself
Is there a way we can use file metadata to establish if the file is a symlink and fail if we happen to be in this case? Or do we actually care about solving this particular edge case?
Robot Results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files📢 Thoughts on this report? Let us know! |
Yes you're suggestions are definitely valid (the part about symlinks which don't point to an existing file also surprised me). Would you be able to take over this PR and do the implementation as per your suggestion? |
didier-wenzek
left a comment
There was a problem hiding this comment.
Approved. Better to squash the commits.
4f5c086 to
88707fe
Compare
Now squashed |
Proposed changes
Support resolving symlink targets files when calling
atomically_write_file_syncandatomically_write_file_async.Note: A symlinks target file will only be resolved if the target file exists, otherwise the path will be the symlink itself.
Types of changes
Paste Link to the issue
#3323
Checklist
cargo fmtas mentioned in CODING_GUIDELINEScargo clippyas mentioned in CODING_GUIDELINESFurther comments