Open
Description
Problem
I'll start with a codeblock as imo it's the most straightforward explanation:
$ ls -l
drwxr-xr-x src
lrwxrwxrwx target -> /home/axlefublr/.cache/wks/hello-world.rs/target
lrwxrwxrwx Cargo.lock -> /home/axlefublr/.cache/wks/hello-world.rs/Cargo.lock
lrwxrwxrwx Cargo.toml -> /home/axlefublr/.cache/wks/hello-world.rs/Cargo.toml
$ cargo --version
cargo 1.87.0-nightly (1d1d646c0 2025-02-21)
$ rustup run stable cargo --version
cargo 1.85.0 (d73d2caf9 2024-12-31)
$ rustup run stable cargo add clap
Updating crates.io index
Adding clap v4.5.31 to dependencies
// --SNIP--
$ ls -l
drwxr-xr-x src
lrwxrwxrwx target -> /home/axlefublr/.cache/wks/hello-world.rs/target
lrwxrwxrwx Cargo.lock -> /home/axlefublr/.cache/wks/hello-world.rs/Cargo.lock
.rw-r--r-- Cargo.toml
$ rm -fr Cargo.toml
$ ln -sf ~/.cache/wks/hello-world.rs/Cargo.toml ./Cargo.toml
$ cargo add clap
Updating crates.io index
Adding clap v4.5.31 to dependencies
// --SNIP--
$ ls -l
drwxr-xr-x src
lrwxrwxrwx target -> /home/axlefublr/.cache/wks/hello-world.rs/target
lrwxrwxrwx Cargo.lock -> /home/axlefublr/.cache/wks/hello-world.rs/Cargo.lock
.rw-r--r-- Cargo.toml
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
mkdir -p test/src
cd test
touch src/main.rs
ln -sf ~/.cache/wks/hello-world.rs/Cargo.toml ./Cargo.toml # path to some other Cargo.toml goes here, instead of the first path
cargo add clap # doesn't matter which dependency you add
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
cargo 1.85.0 (d73d2caf9 2024-12-31)
release: 1.85.0
commit-hash: d73d2caf9e41a39daf2a8d6ce60ec80bf354d2a7
commit-date: 2024-12-31
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: EndeavourOS Rolling Release (rolling) [64-bit]