Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not unwrap as much in clobberregistry #489

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading