Skip to content

Resolve chained symlinks in write_atomic - #17444

Open
cuishuang wants to merge 1 commit into
rust-lang:masterfrom
cuishuang:master
Open

Resolve chained symlinks in write_atomic#17444
cuishuang wants to merge 1 commit into
rust-lang:masterfrom
cuishuang:master

Conversation

@cuishuang

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

Fixes #17443

write_atomic previously resolved only one symlink level. For a chain such as:

A -> B -> C

the atomic replacement was performed on B, replacing the intermediate symlink with a regular file instead of updating the final target C.

This change follows the symlink chain until it reaches the final non-symlink path. Relative targets are resolved against the parent directory of the symlink at each level, while absolute targets continue to work as before.

The implementation also detects repeated resolved paths and returns an error for symlink loops.

How to test and review this PR?

The tests cover:

  • single-level relative symlinks;
  • chained relative symlinks;
  • updating the final target while preserving every symlink in the chain;
  • symlink loops returning an error without modifying the links;
  • existing absolute symlink behavior.

I ran:

cargo +1.98.0 test -p cargo-util
cargo fmt --all -- --check

Signed-off-by: cuishuang <imcusg@gmail.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2026
@rustbot

rustbot commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo
  • Random selection from epage, weihanglo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write_atomic does not resolve chained symlinks

3 participants