diff --git a/crates/rattler/src/install/clobber_registry.rs b/crates/rattler/src/install/clobber_registry.rs index 3c9a62570..f571017b6 100644 --- a/crates/rattler/src/install/clobber_registry.rs +++ b/crates/rattler/src/install/clobber_registry.rs @@ -835,7 +835,7 @@ mod tests { .with_prefix_records(&prefix_records) .finish(); - execute_transaction( + let result = execute_transaction( transaction, target_prefix.path(), &reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()), @@ -845,6 +845,8 @@ mod tests { ) .await; + println!("== RESULT: {:?}", result.clobbered_paths); + assert_check_files( target_prefix.path(), &[ @@ -867,6 +869,95 @@ mod tests { ); } + #[tokio::test] + async fn test_self_clobber_update() { + // Create a transaction + let repodata_record_1 = get_repodata_record( + get_test_data_dir().join("clobber/clobber-1-0.1.0-h4616a5c_0.tar.bz2"), + ); + + let transaction = transaction::Transaction:: { + operations: vec![TransactionOperation::Install(repodata_record_1.clone())], + python_info: None, + current_python_info: None, + platform: Platform::current(), + }; + + // execute transaction + let target_prefix = tempfile::tempdir().unwrap(); + + let packages_dir = tempfile::tempdir().unwrap(); + let cache = PackageCache::new(packages_dir.path()); + + execute_transaction( + transaction, + target_prefix.path(), + &reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()), + &cache, + &InstallDriver::default(), + &InstallOptions::default(), + ) + .await; + + // check that the files are there + assert_check_files( + target_prefix.path(), + &[ + "clobber.txt", + "another-clobber.txt", + ], + ); + + let mut prefix_records = PrefixRecord::collect_from_prefix(target_prefix.path()).unwrap(); + prefix_records.sort_by(|a, b| { + a.repodata_record + .package_record + .name + .as_normalized() + .cmp(b.repodata_record.package_record.name.as_normalized()) + }); + + // Reinstall the same package + let transaction = transaction::Transaction:: { + operations: vec![TransactionOperation::Change { + old: prefix_records[0].clone(), + new: repodata_record_1, + }], + python_info: None, + current_python_info: None, + platform: Platform::current(), + }; + + + let install_driver = InstallDriver::builder() + .with_prefix_records(&prefix_records) + .finish(); + + install_driver.pre_process(&transaction, target_prefix.path()).unwrap(); + let dl_client = reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()); + for op in &transaction.operations { + execute_operation( + target_prefix.path(), + &dl_client, + &cache, + &install_driver, + op.clone(), + &InstallOptions::default(), + ) + .await; + } + + // Check what files are in the prefix now (note that unclobbering wasn't run yet) + // But also, this is a reinstall so the files should just be overwritten. + assert_check_files( + target_prefix.path(), + &[ + "clobber.txt", + "another-clobber.txt", + ], + ); + } + #[tokio::test] async fn test_clobber_update_and_remove() { // Create a transaction diff --git a/crates/rattler/src/install/test_utils.rs b/crates/rattler/src/install/test_utils.rs index 2ef6510e6..a761e99dc 100644 --- a/crates/rattler/src/install/test_utils.rs +++ b/crates/rattler/src/install/test_utils.rs @@ -10,6 +10,8 @@ use crate::{ package_cache::PackageCache, }; +use super::driver::PostProcessResult; + /// Install a package into the environment and write a `conda-meta` file that /// contains information about how the file was linked. pub async fn install_package_to_environment( @@ -124,7 +126,7 @@ pub async fn execute_transaction( package_cache: &PackageCache, install_driver: &InstallDriver, install_options: &InstallOptions, -) { +) -> PostProcessResult { install_driver .pre_process(&transaction, target_prefix) .unwrap(); @@ -143,7 +145,7 @@ pub async fn execute_transaction( install_driver .post_process(&transaction, target_prefix) - .unwrap(); + .unwrap() } pub fn find_prefix_record<'a>(