Repository navigation
Fix relative symlink handling in write_atomic - #17362
Conversation
|
r? @weihanglo rustbot has assigned @weihanglo. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@weihanglo Would you mind taking a look at this write_atomic symlink fix when you have a chance? read_link() returns relative targets as stored, but write_atomic was resolving them relative to Cargo's process working directory instead of the symlink's parent. The fix resolves the target against the parent while preserving absolute-target behavior, with a focused regression test. Thanks! |
Add a regression test that records the current failure when a symlink target is relative to its parent directory. Signed-off-by: cuishuang <imcusg@gmail.com>
Interpret a relative symlink target relative to the directory containing the symlink before creating the temporary file. Signed-off-by: cuishuang <imcusg@gmail.com>
Thanks for pointing this out. I opened a follow-up issue for chained symlink resolution: #17443 I also have a preliminary implementation there. There are still a few design details to discuss, especially symlink loops and dangling targets. #17444 When you have time, feedback or a review would be very helpful. 😄 |
Update cargo submodule 6 commits in 3c0b534756e166d12eb9fd2e1abfe5b42ac6101e..7941be6fb416b4cd9666aef7b858dfea25587a8c 2026-09-04 17:03:10 +0000 to 2026-09-11 20:47:37 +0000 - fix(install): use packaged lockfile by default (rust-lang/cargo#17388) - test: add more comprehensive workspace feature unification tests (rust-lang/cargo#17466) - chore(deps): update crossbeam-epoch to 0.9.21 (rust-lang/cargo#17427) - Fixed stale comment about fingerprint checking method (rust-lang/cargo#17450) - docs(lints): how to configure Cargo lints (rust-lang/cargo#17441) - Fix relative symlink handling in write_atomic (rust-lang/cargo#17362) r? ghost
What does this PR try to resolve?
Fixes #17361.
cargo_util::paths::write_atomicfollows symlinks before performing an atomic write. However,fs::read_linkreturns a relative target exactly as stored in the symlink.The returned target was previously used directly, causing subsequent filesystem operations to interpret it relative to Cargo's process working directory. This could make the write fail or overwrite an unrelated file.
This change resolves the target against the symlink's parent directory:
Path::joinpreserves absolute targets, so the existing behavior for absolute symlinks is unchanged.How to test and review this PR?
A new unit test creates a symlink with a relative target in a directory different from the process working directory. The test verifies that:
I ran:
All 12 unit tests and the
cargo-utildoc-test passed.