Skip to content
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

Source Replacement not working #107

Closed
litzh opened this issue Sep 10, 2019 · 5 comments
Closed

Source Replacement not working #107

litzh opened this issue Sep 10, 2019 · 5 comments
Labels

Comments

@litzh
Copy link

litzh commented Sep 10, 2019

$ 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'
@nabijaczleweli
Copy link
Owner

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?

@litzh
Copy link
Author

litzh commented Sep 10, 2019

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.

@nabijaczleweli
Copy link
Owner

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")?;
 

@litzh
Copy link
Author

litzh commented Sep 10, 2019

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

Thanks for your help.

@nabijaczleweli
Copy link
Owner

Released in v1.8.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants