From 729c828cd05e31320cc7732885f2f3ee2efdea7c Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Thu, 15 Jun 2023 17:22:37 +0200 Subject: [PATCH] Fixup rebase --- src/bare_index.rs | 21 ++++----------------- src/sparse_index.rs | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/bare_index.rs b/src/bare_index.rs index dc84e7c9..5dae1253 100644 --- a/src/bare_index.rs +++ b/src/bare_index.rs @@ -4,7 +4,7 @@ use crate::{error::CratesIterError, path_max_byte_len, Crate, Error, IndexConfig use git2::Repository; use std::fmt; use std::path::{Path, PathBuf}; -use std::{fs, io}; +use std::io; /// The default URL of the crates.io index for use with git, see [`Index::with_path`] pub const INDEX_GIT_URL: &str = "https://github.com/rust-lang/crates.io-index"; @@ -79,21 +79,8 @@ impl Index { /// Note this function takes the `CARGO_HOME` environment variable into account #[inline] pub fn new_cargo_default() -> Result { - let config: toml::Value; - let url = if let Some(path) = find_cargo_config() { - config = toml::from_str(&fs::read_to_string(path)?) - .map_err(Error::Toml)?; - config.get("source").and_then(|sources| - sources.get("crates-io") - .and_then(|v| v.get("replace-with")) - .and_then(|v| v.as_str()) - .and_then(|v| sources.get(v)) - .and_then(|v| v.get("registry")) - .and_then(|v| v.as_str())) - } else { - None - }; - Self::from_url(url.unwrap_or(crate::INDEX_GIT_URL)) + let url = crate::config::get_crates_io_replacement(None, None)?; + Self::from_url(url.as_deref().unwrap_or(crate::INDEX_GIT_URL)) } /// Creates a bare index from a provided URL, opening the same location on @@ -247,7 +234,7 @@ impl Index { cache_path.push(".cache"); cache_path.push(&rel_path); if let Ok(cache_bytes) = std::fs::read(&cache_path) { - if let Ok(krate) = Crate::from_cache_slice(&cache_bytes, &self.head_str) { + if let Ok(krate) = Crate::from_cache_slice(&cache_bytes, Some(&self.head_str)) { return Some(krate); } } diff --git a/src/sparse_index.rs b/src/sparse_index.rs index 990ea059..ffdd7937 100644 --- a/src/sparse_index.rs +++ b/src/sparse_index.rs @@ -73,7 +73,7 @@ impl Index { let cache_path = self.cache_path(name) .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "bad name"))?; - let cache_bytes = std::fs::read(&cache_path)?; + let cache_bytes = std::fs::read(cache_path)?; Ok(Crate::from_cache_slice(&cache_bytes, None)?) } @@ -113,7 +113,7 @@ impl Index { /// `etag` or `last-modified` pub fn read_cache_version(&self, name: &str) -> Option { let cache_path = self.cache_path(name)?; - let bytes = std::fs::read(&cache_path).ok()?; + let bytes = std::fs::read(cache_path).ok()?; const CURRENT_CACHE_VERSION: u8 = 3; const CURRENT_INDEX_FORMAT_VERSION: u32 = 2;