mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00

### What does this PR try to resolve? This PR fixes a bug where `cargo add` breaks symlinks to Cargo.toml files. Currently, when Cargo.toml is a symlink and `cargo add` is used to add a dependency, the symlink is replaced with a regular file, breaking the link to the original target file. This issue was reported in #15241 where a user who relies on symlinked Cargo.toml files found that `cargo add` breaks their workflow. Fixes #15241 ### How should we test and review this PR? I've modified `LocalManifest::write()` to check if the path is a symlink, and if so, follow it to get the actual target path. This ensures we write to the actual file rather than replacing the symlink. I've also added a test in `tests/testsuite/cargo_add/symlink.rs` that: 1. Creates a symlinked Cargo.toml file 2. Runs `cargo add` to add a dependency 3. Verifies the symlink is preserved and the dependency is added to the target file I've manually tested this fix and confirmed it works correctly.
This crate is maintained by the Cargo team, primarily for use by Cargo and not intended for external use (except as a transitive dependency). This crate may make major changes to its APIs or be deprecated without warning.