Skip to content

Commit

Permalink
Fixup rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Jun 15, 2023
1 parent 717815e commit 729c828
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
21 changes: 4 additions & 17 deletions src/bare_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -79,21 +79,8 @@ impl Index {
/// Note this function takes the `CARGO_HOME` environment variable into account
#[inline]
pub fn new_cargo_default() -> Result<Self, Error> {
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
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sparse_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
}

Expand Down Expand Up @@ -113,7 +113,7 @@ impl Index {
/// `etag` or `last-modified`
pub fn read_cache_version(&self, name: &str) -> Option<String> {
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;
Expand Down

0 comments on commit 729c828

Please sign in to comment.