Skip to content

Commit

Permalink
add drop bomb
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jan 11, 2024
1 parent 0b6da7b commit 3fa93c6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/rattler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bytes = "1.5.0"
chrono = { version = "0.4.31", default-features = false, features = ["std", "serde", "alloc"] }
digest = "0.10.7"
dirs = "5.0.1"
drop_bomb = "0.1.5"
futures = "0.3.28"
fxhash = "0.2.1"
hex = "0.4.3"
Expand Down
20 changes: 18 additions & 2 deletions crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ use std::{
path::{Path, PathBuf},
};

use drop_bomb::DropBomb;
use rattler_conda_types::{package::PathsJson, PackageName, PrefixRecord};

/// A registry for clobbering files
/// The registry keeps track of all files that are installed by a package and
/// can be used to rename files that are already installed by another package.
#[derive(Default, Debug)]
#[derive(Debug)]
pub struct ClobberRegistry {
paths_registry: HashMap<PathBuf, usize>,
clobbers: HashMap<PathBuf, Vec<usize>>,
package_names: Vec<PackageName>,
drop_bomb: DropBomb,
}

impl Default for ClobberRegistry {
fn default() -> Self {
Self {
paths_registry: HashMap::new(),
clobbers: HashMap::new(),
package_names: Vec::new(),
drop_bomb: DropBomb::new(
"did not call post_process on InstallDriver / ClobberRegistry",
),
}
}
}

static CLOBBER_TEMPLATE: &str = "__clobber-from-";
Expand Down Expand Up @@ -131,10 +146,11 @@ impl ClobberRegistry {

/// Unclobber the paths after all installation steps have been completed.
pub fn post_process(
&self,
&mut self,
sorted_prefix_records: &[&PrefixRecord],
target_prefix: &Path,
) -> Result<(), std::io::Error> {
self.drop_bomb.defuse();
let sorted_names = sorted_prefix_records
.iter()
.map(|p| p.repodata_record.package_record.name.clone())
Expand Down
14 changes: 13 additions & 1 deletion crates/rattler/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,12 @@ mod test {
})
.await;

// test doesn't write conda-meta, so we ignore the post processing
let prefix_records = vec![];
install_driver
.post_process(&prefix_records, target_dir.path())
.unwrap();

// Run the python command and validate the version it outputs
let python_path = if Platform::current().is_windows() {
"python.exe"
Expand Down Expand Up @@ -745,16 +751,22 @@ mod test {
)
.unwrap();

let install_driver = InstallDriver::default();

// Link the package
let paths = link_package(
package_dir.path(),
environment_dir.path(),
&InstallDriver::default(),
&install_driver,
InstallOptions::default(),
)
.await
.unwrap();

install_driver
.post_process(&vec![], environment_dir.path())
.unwrap();

insta::assert_yaml_snapshot!(paths);
}
}
7 changes: 6 additions & 1 deletion crates/rattler/src/install/unlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ mod tests {
..InstallOptions::default()
};

let install_driver = InstallDriver::default();
// Link the package
let paths = link_package(
package_dir.path(),
target_prefix,
&InstallDriver::default(),
&install_driver,
install_options,
)
.await
Expand All @@ -199,6 +200,10 @@ mod tests {
let prefix_record =
PrefixRecord::from_repodata_record(repodata_record, None, None, paths, None, None);

install_driver
.post_process(&vec![prefix_record.clone()], target_prefix)
.unwrap();

return prefix_record;
}

Expand Down

0 comments on commit 3fa93c6

Please sign in to comment.