nabijaczleweli / cargo-update

A cargo subcommand for checking and applying updates to installed executables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update fails when a package is installed from a custom registry

SolidTux opened this issue · comments

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?

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.

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.

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

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

Released in v3.0.0!

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(-)

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.

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.

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[..]) {

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 ...

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 🤦‍♂️

😆 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?

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.

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

Glad I could help!

But it only works, when both entries are present 🤷‍♂️ Thank you for helping!