Skip to content

Commit

Permalink
load_and_overlay -> load_unreplaced
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Jun 4, 2024
1 parent d395d36 commit 07b17b9
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,6 @@ impl<'gctx> SourceConfigMap<'gctx> {
self.gctx
}

fn load_and_overlay(
&self,
id: SourceId,
yanked_whitelist: &HashSet<PackageId>,
) -> CargoResult<Box<dyn Source + 'gctx>> {
let src = id.load(self.gctx, yanked_whitelist)?;
if let Some(overlay_id) = self.overlays.get(&id) {
let overlay = overlay_id.load(self.gctx(), yanked_whitelist)?;
Ok(Box::new(DependencyConfusionThreatOverlaySource::new(
overlay, src,
)))
} else {
Ok(src)
}
}

/// Gets the [`Source`] for a given [`SourceId`].
///
/// * `yanked_whitelist` --- Packages allowed to be used, even if they are yanked.
Expand All @@ -172,7 +156,7 @@ impl<'gctx> SourceConfigMap<'gctx> {
debug!("loading: {}", id);

let Some(mut name) = self.id2name.get(&id) else {
return self.load_and_overlay(id, yanked_whitelist);
return self.load_unreplaced(id, yanked_whitelist);
};
let mut cfg_loc = "";
let orig_name = name;
Expand All @@ -197,7 +181,7 @@ impl<'gctx> SourceConfigMap<'gctx> {
name = s;
cfg_loc = c;
}
None if id == cfg.id => return self.load_and_overlay(id, yanked_whitelist),
None if id == cfg.id => return self.load_unreplaced(id, yanked_whitelist),
None => {
break cfg.id.with_precise_from(id);
}
Expand All @@ -214,7 +198,7 @@ impl<'gctx> SourceConfigMap<'gctx> {
}
};

let new_src = self.load_and_overlay(
let new_src = self.load_unreplaced(
new_id,
&yanked_whitelist
.iter()
Expand Down Expand Up @@ -251,6 +235,23 @@ restore the source replacement configuration to continue the build
Ok(Box::new(ReplacedSource::new(id, new_id, new_src)))
}

/// Gets the [`Source`] for a given [`SourceId`] without performing any source replacement.
fn load_unreplaced(
&self,
id: SourceId,
yanked_whitelist: &HashSet<PackageId>,
) -> CargoResult<Box<dyn Source + 'gctx>> {
let src = id.load(self.gctx, yanked_whitelist)?;
if let Some(overlay_id) = self.overlays.get(&id) {
let overlay = overlay_id.load(self.gctx(), yanked_whitelist)?;
Ok(Box::new(DependencyConfusionThreatOverlaySource::new(
overlay, src,
)))
} else {
Ok(src)
}
}

/// Adds a source config with an associated name.
fn add(&mut self, name: &str, cfg: SourceConfig) -> CargoResult<()> {
if let Some(old_name) = self.id2name.insert(cfg.id, name.to_string()) {
Expand Down

0 comments on commit 07b17b9

Please sign in to comment.