rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.63k stars 2.4k forks source link

Change `cargo install` error on corrupt metadata to warning #12232

Open jarkkojs opened 1 year ago

jarkkojs commented 1 year ago

Problem

This transcript emphasizes the problem:

$ cargo uninstall zellij
error: corrupt metadata, `/home/jarkko/.cargo/bin/zellij` does not exist when it should

$ touch .cargo/bin/zellij

$ cargo uninstall zellij
    Removing /home/jarkko/.cargo/bin/zellij

$ cargo uninstall zellij
error: package ID specification `zellij` did not match any packages

Why is exiting empty file better than non-existing file? Since cargo does not care of the contents, why is it logical to fail ENOENT case?

Steps

No response

Possible Solution(s)

Change error to warning and proceed on removing the meta-data.

Notes

No response

Version

No response

epage commented 1 year ago

If I'm understanding correctly, this is only happening if you do:

$ cargo install zellij
$ rm ~/.cargo/bin/zellij
$ cargo uninstall zellij

Is that correct?

A benefit I see to this is it would allow someone to clean up their install-metadata

I can see us being extra cautious at removing any files if one of the expected files isn't there. Deleting is inherently destructive and caution should be exercised.

The part that isn't to clear to me though is what the use case is where this would happen enough (or even once) for this to be noticeable.

LeSnake04 commented 4 months ago

I think it makes sense to add something like cargo uninstall --force/-f for cases like this. I got this error trying to clean some unused packages, so deleting the metadata and leftover dirs would make sense in that case.