Skip to content

Commit

Permalink
do not unwrap and use PackageName as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jan 23, 2024
1 parent 2650305 commit 2820a59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ impl ClobberRegistry {
.package_names
.iter()
.position(|n| n == originating_package)
.unwrap();
.expect("package not found even though it was just added");

let path = *path;
registry
.clobbers
.entry(path.clone())
.or_insert_with(|| vec![*registry.paths_registry.get(path).unwrap()])
.or_insert_with(|| {
if let Some(other_idx) = registry.paths_registry.get(path) {
vec![*other_idx]
} else {
Vec::new()
}
})
.push(idx);
}

Expand All @@ -97,21 +103,16 @@ impl ClobberRegistry {
/// will "unclobber" the files after all packages have been installed.
pub fn register_paths(
&mut self,
name: &str,
name: &PackageName,
paths_json: &PathsJson,
) -> HashMap<PathBuf, PathBuf> {
let mut clobber_paths = HashMap::new();

// check if we have the package name already registered
let name_idx = if let Some(idx) = self
.package_names
.iter()
.position(|n| n.as_normalized() == name)
{
let name_idx = if let Some(idx) = self.package_names.iter().position(|n| n == name) {
idx
} else {
self.package_names
.push(PackageName::try_from(name).unwrap());
self.package_names.push(name.clone());
self.package_names.len() - 1
};

Expand Down
2 changes: 1 addition & 1 deletion crates/rattler/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub async fn link_package(
let clobber_paths = Arc::new(
driver
.clobber_registry()
.register_paths(index_json.name.as_normalized(), &paths_json),
.register_paths(&index_json.name, &paths_json),
);

// Start linking all package files in parallel
Expand Down

0 comments on commit 2820a59

Please sign in to comment.