-
Notifications
You must be signed in to change notification settings - Fork 2.6k
cargo add overwrites a symlink Cargo.toml #15241
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
Comments
for those curious to know why I'm using a Cargo.toml symlink in the first place, read my blog post on that (I didn't make this issue for advertising; I'm just answering a very likely question in advance) |
btw are you aware of native support for cargo script? I posted an update today on it at https://blog.rust-lang.org/inside-rust/2025/02/27/this-development-cycle-in-cargo-1.86.html#cargo-script I would be interested in performance feedback. While we likely won't be doing any |
@epage I'm glad that cargo-script is being worked on on the core side, but it's probably not going to plug all of my holes as well as my current system does rust-analyzer support I heard is coming, which is great news! I avoid writing fish scripts and instead write fish functions specifically because of the startup cost; I can't see cargo-script not having that cost, unfortunately |
better way to phrase things: I have a rust binary generating system, not a rust scripting system. so I think I'm just not the audience for cargo-script, lol |
When Cargo.toml is a symlink, cargo add was overwriting it with a regular file. This change follows the symlink and writes to the target file instead, preserving the symlink structure. Fixes rust-lang#15241
When Cargo.toml is a symlink, cargo add was overwriting it with a regular file. This change follows the symlink and writes to the target file instead, preserving the symlink structure. Fixes rust-lang#15241
When Cargo.toml is a symlink, cargo add was overwriting it with a regular file. This change follows the symlink and writes to the target file instead, preserving the symlink structure. Fixes rust-lang#15241
When Cargo.toml is a symlink, cargo add was overwriting it with a regular file. This change follows the symlink and writes to the target file instead, preserving the symlink structure. Fixes rust-lang#15241
When cargo add is used on a project where Cargo.toml is a symlink, it now follows the symlink and writes to the target file instead of replacing the symlink with a regular file. This is achieved by updating write_atomic() to detect symlinks and resolve them before writing. Fixes rust-lang#15241
- Preserve symlinks when writing files atomically in write_atomic() - Update test to verify correct symlink preservation behavior - Apply rustfmt formatting This fixes the issue where cargo add would replace symlinked Cargo.toml files with regular files, breaking the symlink to the original target. Fixes rust-lang#15241
### 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.
yaaaay! 💃💃💃 |
Uh oh!
There was an error while loading. Please reload this page.
Problem
I'll start with a codeblock as imo it's the most straightforward explanation:
I have Cargo.toml symlinked to the real Cargo.toml somewhere else. When using
cargo add
, I expect the symlink to not be broken. However,cargo add
overrides the symlink into being a normal file, breaking the symlink tie to that other Cargo.toml.I don't think that's intentional.
Steps
viola.
stat
the Cargo.toml to see that it's now a regular file, rather than a symlink.the target Cargo.toml stays untouched, btw
Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: