nabijaczleweli / cargo-update

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

Update fails when a package is installed from a custom registry #128

Closed SolidTux closed 4 years ago

SolidTux commented 4 years ago

I have a binary which is installed from a custom registry. Now cargo install-update -l or cargo install-update -a fails with

    Updating registry 'https://github.com/rust-lang/crates.io-index'

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "package ... not found"', src/libcore/result.rs:1188:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is there a way to search all configured registries or maybe even just skip the failed packages?

nabijaczleweli commented 4 years ago

Can you test current master branch with the referenced commit?

It has an experimental implementation of generic registry handling, so it should work for your usecase – your package should update from the right registry automatically and you should be able to install it from there via (registry_url):package_name.

SolidTux commented 4 years ago

It seems to recognize the correct registry, but it tries to open the wrong registry directory:

Failed to open registry repository at /home/daniel/.cargo/registry/index/dl.cloudsmith.io-1c9cb99b5e769975.

The correct directory would be /home/daniel/.cargo/registry/index/dl.cloudsmith.io-c9a963c300d41cda.

nabijaczleweli commented 4 years ago

The Cargo code for this is Very Good and Reproducible:tm:, but I'm pretty sure referenced commit above should do it?

SolidTux commented 4 years ago

Seems to work! Thank you for the very fast response and fix!

nabijaczleweli commented 4 years ago

Released in v3.0.0!

SolidTux commented 4 years ago

Now it doesn't work anymore and I get

Couldn't get registry for gitmanager: Non-crates.io registry specified and $URL couldn't be found in the config file at /home/daniel/.cargo/config. Due to a Cargo limitation we will not be able to install from there until it's given a [source.NAME] in that file!

Even though I have an entry with this exact URL in ~/.cargo/config Bisecting yields

1b27f6e43940f49551a730e427b1762456e20e8c is the first bad commit
commit 1b27f6e43940f49551a730e427b1762456e20e8c
Author: nabijaczleweli <nabijaczleweli@gmail.com>
Date:   Wed Mar 11 02:11:48 2020 +0100

    Work around Cargo not accepting registry URLs in --registry

 src/main.rs                | 38 ++++++++------------------------------
 src/ops/mod.rs             | 26 ++++++++++++++++++++------
 tests/ops/get_index_url.rs | 30 +++++++++++++++++++++++++++---
 3 files changed, 55 insertions(+), 39 deletions(-)
nabijaczleweli commented 4 years ago

That's interesting... What's your cargo version? I get "cargo 1.41.0 (626f0f40e 2019-12-03)", which gave me errors when I fed it an URL to --registry, which I "worked around" in that commit by replacing "invalid character ':' in registry" from Cargo with a nicer error if I couldn't find a source name that Cargo expects.

SolidTux commented 4 years ago

Interesting ... I've also got cargo 1.41.0 (626f0f40e 2019-12-03). When installing with cargo install --repository ... only a name works for me.

nabijaczleweli commented 4 years ago

By way of test, can try with this patch, which'll revert to the previous behaviour of passing the URL to the registry (and say if it does so)? It shouldn't work, but ..?

diff --git a/src/ops/mod.rs b/src/ops/mod.rs
index cd4fa30f7..fbb2462ff 100644
--- a/src/ops/mod.rs
+++ b/src/ops/mod.rs
@@ -900,11 +900,8 @@ pub fn get_index_url(crates_file: &Path, registry: &str) -> Result<(String, Cow<
     }

     if Url::parse(&cur_source).is_ok() {
-        Err(format!("Non-crates.io registry specified and {} couldn't be found in the config file at {}. \
-                     Due to a Cargo limitation we will not be able to install from there \
-                     until it's given a [source.NAME] in that file!",
-                    cur_source,
-                    config_file.display()))?
+        eprintln!("WARN: Passing {} as --registry", cur_source);
+        return Ok((cur_source.to_string(), cur_source.to_string().into()));
     }

     while let Some(repl) = replacements.get(&cur_source[..]) {
SolidTux commented 4 years ago

Listing at least works, I'll try to update a package and see what happens.

This is the repo by the way, maybe it's about the repo and not the program ...

SolidTux commented 4 years ago

Interesting ... with the patch the command show no error, but also the update is not recognized. And without the patch the error is shown. Sorry, I never tested if the updating works, only if the package is listed :man_facepalming:

nabijaczleweli commented 4 years ago

😆 zall good, who hasn't been there lol

I think you're gonna have to add the source with, at minimum,

[source.cloudsmith]
registry = "https://dl.cloudsmith.io/public/solidtux/cargo/cargo/index.git"

in your ~/.cargo/config, to install/update packages from there?

SolidTux commented 4 years ago

My ~/.cargo/config looks like

[registries]
solidtux-cargo = { index = "https://dl.cloudsmith.io/public/solidtux/cargo/cargo/index.git" }

because the cargo book and the cloudsmith help. But when I add

[source.solidtux-cargo]
registry = "https://dl.cloudsmith.io/public/solidtux/cargo/cargo/index.git"

as you suggested, everything works.

What exactly is the difference between registries.NAME.index and source.NAME.registry?

Edit: Apparently the index version is deprecated according to the reference. So it seems that the other sources are just outdated.

nabijaczleweli commented 4 years ago

Oh neat, I didn't actually know about those before! This might warrant an issue on cloudsmith's side, too.

Glad I could help!

SolidTux commented 4 years ago

But it only works, when both entries are present :man_shrugging: Thank you for helping!