diff --git a/src/dirs.rs b/src/dirs.rs index d771c278..d67902b5 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -1,11 +1,11 @@ use crate::Error; -/// Get the disk location of the specified url, as well as its canonical form, -/// exactly as cargo would +/// Get the disk location of the specified `url`, as well as its canonical form, +/// exactly as cargo would. /// /// `cargo_home` is used to root the directory at specific location, if not -/// specified `CARGO_HOME` or else the default cargo location is used as the root -pub(crate) fn get_index_details( +/// specified `CARGO_HOME` or else the default cargo location is used as the root. +pub fn local_path_and_canonical_url( url: &str, cargo_home: Option<&std::path::Path>, ) -> Result<(std::path::PathBuf, String), Error> { diff --git a/src/git/mod.rs b/src/git/mod.rs index 7c2d20f6..e423471e 100644 --- a/src/git/mod.rs +++ b/src/git/mod.rs @@ -1,6 +1,6 @@ #![allow(clippy::result_large_err)] use crate::dedupe::DedupeContext; -use crate::dirs::{crate_name_to_relative_path, get_index_details}; +use crate::dirs::{crate_name_to_relative_path, local_path_and_canonical_url}; use crate::error::GixError; use crate::{path_max_byte_len, Crate, Error, IndexConfig, GitIndex}; use gix::config::tree::Key; @@ -82,7 +82,7 @@ impl GitIndex { /// /// It can be used to access custom registries. pub fn from_url(url: &str) -> Result { - let (path, canonical_url) = get_index_details(url, None)?; + let (path, canonical_url) = local_path_and_canonical_url(url, None)?; Self::from_path_and_url(path, canonical_url) } diff --git a/src/lib.rs b/src/lib.rs index 3381fd98..e3f01244 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,6 +134,7 @@ pub use config::IndexConfig; mod dedupe; mod dirs; +pub use dirs::local_path_and_canonical_url; /// Re-exports in case you want to inspect specific error details pub mod error; diff --git a/src/sparse.rs b/src/sparse.rs index 4479d86a..ea2a5765 100644 --- a/src/sparse.rs +++ b/src/sparse.rs @@ -1,7 +1,7 @@ use std::io; use std::path::{Path, PathBuf}; -use crate::{Crate, dirs::get_index_details, Error, IndexConfig, path_max_byte_len, SparseIndex}; +use crate::{Crate, dirs::local_path_and_canonical_url, Error, IndexConfig, path_max_byte_len, SparseIndex}; use crate::dirs::crate_name_to_relative_path; /// The default URL of the crates.io HTTP index, see [`SparseIndex::from_url`] and [`SparseIndex::new_cargo_default`] @@ -40,7 +40,7 @@ impl SparseIndex { return Err(Error::Url(url.to_owned())); } - let (path, url) = get_index_details(url, Some(cargo_home.as_ref()))?; + let (path, url) = local_path_and_canonical_url(url, Some(cargo_home.as_ref()))?; Ok(Self::at_path(path, url)) }