Skip to content

cargo uninstall with a sparse registry removes "sparse+" from the urls in .cargo.toml and .cargo2.json breaking install/uninstall #11751

Closed
@jsumner

Description

@jsumner

Problem

When running "cargo uninstall" the "sparse" prefix is removed from the urls in .crates.toml and .crates2.json files. Breaking the file and stopping cargo install/uninstall from working.

The url in both .crates.toml and .crates2.json both require a prefix. Typically this is "registry", however when using a sparse registry it should be "sparse". Some of the code expects this and reading the files now fails.

Install works fine against sparse registries - it is the act of uninstalling is what breaks the files. Other cargo commands seem fine against a sparse repo as well.

Steps

  1. cargo install yaml2json
  2. cargo install grex
  3. edit ~/.cargo/.crates.toml and change url for grex from registry+... to sparse+...
    From: grex 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = ["grex"]
    To: grex 1.4.1 (sparse+https://github.com/rust-lang/crates.io-index)" = ["grex"]
  4. cargo uninstall yaml2json
  5. check ~/.cargo/crates.toml - grex url is now http... missing the sparse at the start.
    Output: grex 1.4.1 (https://github.com/rust-lang/crates.io-index)" = ["grex"]

This reproduces without having the actually have a sparse registry. If you have a sparse registry you can skip step 3 as that's just a hack to mimic.

Possible Solution(s)

src/cargo/core/source/source_id.rs - line 724 writes the url as "{url}", however I think it should be writing as "sparse+{url}" based on what the rest of the function is doing.

A workaround for anyone hitting the same problem is to add the "sparse+" back into the crates file (need to do both).

Notes

I've made the change in a test environment and it seems to do the trick, however I don't know what other knock on effects this change may have.

Version

cargo 1.67.1 (8ecd4f20a 2023-01-10)
release: 1.67.1
commit-hash: 8ecd4f20a9efb626975ac18a016d480dc7183d9b
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Arch Linux [64-bit]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions