Skip to content

Commit

Permalink
fix: do not compare size when comparing two crate metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
  • Loading branch information
iamsauravsharma committed Jan 11, 2025
1 parent 767db5d commit 2b20320
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 9 additions & 14 deletions src/crate_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ impl Ord for CrateMetaData {
match self.name.cmp(&other.name) {
Ordering::Equal => {
match self.version.cmp(&other.version) {
Ordering::Equal => {
match self.size.cmp(&other.size) {
Ordering::Less => self.source.cmp(&other.source),
ord => ord,
}
}
Ordering::Equal => self.source.cmp(&other.source),
ord => ord,
}
}
Expand Down Expand Up @@ -105,7 +100,7 @@ struct IndexConfig {
/// stores different crate size and name information
#[derive(Default)]
pub(crate) struct CrateDetail {
source_info: HashMap<String, Url>,
source_infos: HashMap<String, Url>,
bin: HashSet<CrateMetaData>,
git_crates_source: HashSet<CrateMetaData>,
registry_crates_source: HashSet<CrateMetaData>,
Expand All @@ -116,7 +111,7 @@ pub(crate) struct CrateDetail {
impl CrateDetail {
/// Crate new index info
pub(crate) fn new(index_dir: &Path, db_dir: &Path) -> Result<Self> {
let mut source_info = HashMap::new();
let mut source_infos = HashMap::new();
if index_dir.exists() && index_dir.is_dir() {
for entry in fs::read_dir(index_dir)? {
let registry_dir = entry?.path();
Expand Down Expand Up @@ -144,7 +139,7 @@ impl CrateDetail {
.split_whitespace()
.last()
.context("failed to get url part from content")?;
source_info.insert(
source_infos.insert(
registry_file_name.to_string(),
Url::from_str(url_path).context("fail FETCH_HEAD url conversion")?,
);
Expand All @@ -164,7 +159,7 @@ impl CrateDetail {
let scheme = scheme_url.scheme();
let url = Url::from_str(&format!("{scheme}://{domain}"))
.context("failed sparse registry index url")?;
source_info.insert(registry_file_name.to_string(), url);
source_infos.insert(registry_file_name.to_string(), url);
}
}
}
Expand All @@ -184,21 +179,21 @@ impl CrateDetail {
.split_whitespace()
.last()
.context("failed to get url part from content")?;
source_info.insert(
source_infos.insert(
git_file_name.to_string(),
Url::from_str(url_path).context("failed to convert db dir FETCH_HEAD")?,
);
}
}
Ok(Self {
source_info,
source_infos,
..Default::default()
})
}

/// Get index name from url
pub(crate) fn index_names_from_url(&self, url: &Url) -> Vec<String> {
self.source_info
self.source_infos
.iter()
.filter_map(|(key, val)| {
if val == url {
Expand All @@ -212,7 +207,7 @@ impl CrateDetail {

/// Get source infos
pub(crate) fn source_infos(&self) -> &HashMap<String, Url> {
&self.source_info
&self.source_infos
}

/// return bin crates metadata
Expand Down
2 changes: 1 addition & 1 deletion src/list_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ fn read_content(
let file_content = std::fs::read_to_string(cargo_lock_file)
.context("failed to read cargo lock content to string")?;
let cargo_lock_data: LockData =
toml::from_str(&file_content).context("failed to convert to Toml format")?;
toml::from_str(&file_content).context("failed to convert to toml format")?;
if let Some(packages) = cargo_lock_data.package() {
for package in packages {
if let Some(source) = package.source() {
Expand Down

0 comments on commit 2b20320

Please sign in to comment.