nabijaczleweli / cargo-update

A cargo subcommand for checking and applying updates to installed executables
MIT License
1.22k stars 42 forks source link

fix: correct replacing source name #138

Closed DCjanus closed 4 years ago

DCjanus commented 4 years ago

fix: #137

nabijaczleweli commented 4 years ago

This... doesn't look right. Take for example the test you edited: it no longer fully resolves down to tralternative, stopping at the registry it originally resolved the URL/name for; why? What final cargo install invocation are you seeing versus what are you expecting to see?

DCjanus commented 4 years ago

Example config file:

[source.crates-io]
replace-with = "sjtu"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

In this case, origin code, cargo-update would try to cargo install --registry sjtu --version x.y.z my_package, with message Updating registry "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index", which would be failed. Because there is no sjtu registry, it's just a proxy for crates-io.

With this PR, that would be cargo install --registry crates-io --version x.y.z my_package and show me this Updating registry "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index", and works fine in my case.

In fact, registry in cargo install, it means to install package from crates-io or your private registry. And replace-with would not replace registry identity but registry field, which is for public registry proxy.

DCjanus commented 4 years ago

If you are trying to reproduce it, try this:

  1. put my config file in last comment to you cargo home
  2. cargo install --version 3.0.0 cargo-update
  3. cargo install-update cargo-update
nabijaczleweli commented 4 years ago

Thanks for the details, they've allowed me to verify the implementation and this seems like a cargo regression from nightly-2019-08-10-x86_64-unknown-linux-gnu, with nightly-2019-09-10-x86_64-unknown-linux-gnu being the first regressed version I found that exhibits this

I'm going to open an issue on the cargo repository and drink now

nabijaczleweli commented 4 years ago

I also came across (well, "came across", I wrote multiple comments and a 6-commit implementation, maybe I'm just old) https://github.com/nabijaczleweli/cargo-update/issues/128#issuecomment-597887413, which was illuminatory:

I saw cargo install --index URL in the cargo source which'd let us avoid the naming and just use the URLs we deal in anyway but it's only 2 months old, so no dice.

I'll write some documentation when I'm less angry and more sober. Thanks again for your testcases, and, mayhap more importantly, persistence.

nabijaczleweli commented 4 years ago

Can you try adding this to your config:

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

and running an update operation again?

That's what I documented to work in cef1717460a6079f491798b1787e7f887ce06dbc, and a test result from you would be great.

DCjanus commented 4 years ago

Sad to say this: this don't work with me.

Here is my config file:

[source.crates-io]
replace-with = "sjtu"

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

I've tried cargo install-update --all, and got this:

Couldn't get registry for cargo-edit: Couldn't find appropriate source URL for https://github.com/rust-lang/crates.io-index in C:\Users\DCjanus\.cargo\config (resolved to "sjtu").
DCjanus commented 4 years ago

Oh, what a mistake I've made!

I've took a wrong title, it should be source replacement rather than alternate registry.

nabijaczleweli commented 4 years ago

Your entire config unfortunately needs to be:

[source.crates-io]
replace-with = "sjtu"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

Can you try that instead?

VitalyAnkh commented 4 years ago

Can you try that instead?

I met the same problem with @DCjanus, and when I try this config, after running cargo install-update -a, I got

Couldn't get package repository: Couldn't read /home/vitalyr/.cargo/registry/index/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b (index directory for https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index): No such file or directory (os error 2).

So this config doesn't solve the problem.

Actually there are many guides for replacing the official crates.io-index with sjtu's mirror in Chinese Internet, which guide people to set the same .cargo/config with @DCjanus 's. It' s not a good choice to force users to edit their config to use cargo-update.

cargo-update is really awesome, why not improve it by accepting this pr?

nabijaczleweli commented 4 years ago

Because, well, it doesn't actually solve the underlying problem (that being: cargo's stability guarantees are bullshit) (and also it's kinda subtly wrong in what it produces, but that's beside the point). It works entirely by accident because sources.crates-io is the default and so is registries.crates-io.

What's the output of find .cargo/registry/ -maxdepth 2 -type d for you, @VitalyAnkh? Does running cargo install --registry sjtu lazy_static (ignore the error), then running cargo install-update -a again fix the problem?

nabijaczleweli commented 4 years ago

Documentation released in v4.1.0, but I'm open to further troubleshooting if your MIA isn't permanent.