nabijaczleweli / cargo-update

A cargo subcommand for checking and applying updates to installed executables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Source Replacement not working

litzh opened this issue · comments

commented
$ cargo version
cargo 1.37.0 (9edd08916 2019-08-02)
$ cargo install-update --version
cargo-install-update 1.7.0

According to The Cargo Book, Cargo supports the ability to replace one source with another.

Below is my ~/.cargo/config:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

When executing cargo install, Cargo downloads from custom source.

$ cargo install cargo-update
    Updating `git://mirrors.ustc.edu.cn/crates.io-index` index

When executing cargo install-update, Cargo downloads from the default source.

$ cargo install-update -a
    Updating registry 'https://github.com/rust-lang/crates.io-index'

Tested this locally, but if you would be so kind as to check if the newest master with commits above correctly picks up your config and checkout?

commented

It works on Linux and Windows MSVC.

On macOS (both stable and nightly), it still picks the default config.

Cargo versions are all 1.37.0.

Hmm, can you apply the following patch and post the output?

diff --git a/src/main.rs b/src/main.rs
index d3cba3d17..3a1f74908 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -69,10 +69,12 @@ fn actual_main() -> Result<(), i32> {
     }
 
     let registry_url = cargo_update::ops::get_index_url(&crates_file);
+    println!("registry_url {}", registry_url);
     let registry = cargo_update::ops::get_index_path(&opts.cargo_dir.1, Some(&registry_url)).map_err(|e| {
             println!("Couldn't get package repository: {}.", e);
             2
         })?;
+    println!("registry {:?}", registry);
     let mut registry_repo = Repository::open(&registry).map_err(|_| {
             println!("Failed to open registry repository at {}.", registry.display());
             2
diff --git a/src/ops/mod.rs b/src/ops/mod.rs
index 359ee6271..865556633 100644
--- a/src/ops/mod.rs
+++ b/src/ops/mod.rs
@@ -796,8 +796,11 @@ pub fn get_index_url(crates_file: &Path) -> Cow<'static, str> {
 }
 
 fn get_index_url_impl(crates_file: &Path) -> Option<String> {
+    println!("crates_file {:?}", crates_file);
     let config = fs::read_to_string(crates_file.with_file_name("config")).ok()?;
+    println!("config {}", config);
     let config = toml::from_str::<toml::Value>(&config).ok()?;
+    println!("config {:#?}", config);
 
     let sources = config.get("source")?;
 
commented

I fixed a typo in ~/.cargo/config on macOS, and now it works.:dizzy_face:

Thanks for your help.

Released in v1.8.0!