Skip to content

Commit

Permalink
feat: add dirs::TBD to make it possible to know where the index sho…
Browse files Browse the repository at this point in the history
…uld be looked for.

This might be interesting also for tools that deal with the data alone, like `cargo-cache`.
  • Loading branch information
Byron committed Jul 29, 2023
1 parent 965f6e9 commit 0d89352
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/dirs.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -82,7 +82,7 @@ impl GitIndex {
///
/// It can be used to access custom registries.
pub fn from_url(url: &str) -> Result<Self, Error> {
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)
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sparse.rs
Original file line number Diff line number Diff line change
@@ -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`]
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 0d89352

Please sign in to comment.