Fix v1 format for custom registry

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-07-17 01:24:34 +10:00
parent e1ec8a21da
commit 8d85b37834
No known key found for this signature in database
GPG key ID: 76D1E687CA3C4928
5 changed files with 40 additions and 4 deletions

View file

@ -1,4 +1,4 @@
use std::{io, path::PathBuf, sync::Arc};
use std::{fmt::Display, io, path::PathBuf, sync::Arc};
use binstalk_downloader::remote::Client;
use binstalk_types::cargo_toml_binstall::Meta;
@ -73,6 +73,10 @@ impl GitRegistry {
}))
}
pub fn url(&self) -> impl Display + '_ {
&self.0.url
}
/// WARNING: This is a blocking operation.
fn find_crate_matched_ver(
repo: &Repository,

View file

@ -1,6 +1,6 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
use std::{io, str::FromStr, sync::Arc};
use std::{fmt, io, str::FromStr, sync::Arc};
use base16::DecodeError as Base16DecodeError;
use binstalk_downloader::{
@ -197,6 +197,15 @@ impl Registry {
}
}
impl fmt::Display for Registry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Registry::Git(registry) => fmt::Display::fmt(&registry.url(), f),
Registry::Sparse(registry) => fmt::Display::fmt(&registry.url(), f),
}
}
}
impl FromStr for Registry {
type Err = InvalidRegistryError;

View file

@ -1,3 +1,5 @@
use std::fmt::Display;
use binstalk_downloader::remote::{Client, Error as RemoteError};
use binstalk_types::cargo_toml_binstall::Meta;
use cargo_toml_workspace::cargo_toml::Manifest;
@ -28,6 +30,10 @@ impl SparseRegistry {
}
}
pub fn url(&self) -> impl Display + '_ {
&self.url
}
async fn get_dl_template(&self, client: &Client) -> Result<&str, RegistryError> {
self.dl_template
.get_or_try_init(|| {

View file

@ -453,7 +453,17 @@ impl PackageInfo {
.fetch_crate_matched(client, &name, version_req),
)
.await?,
CrateSource::cratesio_registry(),
{
let registry = format!("{}", opts.registry);
if registry == "https://index.crates.io/" {
CrateSource::cratesio_registry()
} else {
CrateSource {
source_type: SourceType::Registry,
url: MaybeOwned::Owned(Url::parse(&registry)?),
}
}
},
),
};

View file

@ -43,20 +43,27 @@ EOF
# Install binaries using default registry in config
"./$1" binstall --force -y cargo-binstall@0.12.0
grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml"
test_cargo_binstall_install
# Install binaries using registry t2 in config
"./$1" binstall --force --registry t2 -y cargo-binstall@0.12.0
grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml"
test_cargo_binstall_install
# Install binaries using registry t3 in env
CARGO_REGISTRIES_t3_INDEX='sparse+https://index.crates.io/' "./$1" binstall --force --registry t3 -y cargo-binstall@0.12.0
test_cargo_binstall_install
grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml"
test_cargo_binstall_install
# Install binaries using index directly
"./$1" binstall --force --index 'sparse+https://index.crates.io/' -y cargo-binstall@0.12.0
grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml"
test_cargo_binstall_install