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: clobbering of directories #783

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
64 changes: 64 additions & 0 deletions crates/rattler/src/install/clobber_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,68 @@

assert_check_files(&target_prefix.path().join("bin"), &["python"]);
}

// This used to hit an expect in the clobbering code
#[tokio::test]
async fn test_directory_clobber() {
// Create a transaction
let repodata_record_with_dir = get_repodata_record(
get_test_data_dir().join("clobber/clobber-with-dir-0.1.0-h4616a5c_0.conda"),
);
let repodata_record_without_dir = get_repodata_record(
get_test_data_dir().join("clobber/clobber-without-dir-0.1.0-h4616a5c_0.conda"),
);

let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![TransactionOperation::Install(repodata_record_with_dir)],
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;

let prefix_records = PrefixRecord::collect_from_prefix(target_prefix.path()).unwrap();

// remove one of the clobbering files
let transaction = transaction::Transaction::<PrefixRecord, RepoDataRecord> {
operations: vec![
TransactionOperation::Remove(prefix_records[0].clone()),
TransactionOperation::Install(repodata_record_without_dir),
],
python_info: None,
current_python_info: None,
platform: Platform::current(),
};

let install_driver = InstallDriver::builder()
.with_prefix_records(&prefix_records)
.finish();

execute_transaction(
transaction,
target_prefix.path(),
&reqwest_middleware::ClientWithMiddleware::from(reqwest::Client::new()),
&cache,
&install_driver,
&InstallOptions::default(),
)
.await;

assert_check_files(&target_prefix.path(), &["dir"]);

Check failure on line 1238 in crates/rattler/src/install/clobber_registry.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

this expression creates a reference which is immediately dereferenced by the compiler
}
}
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions test-data/clobber/recipe/recipe-with-dir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
recipe:
name: clobber-with-dir
version: 0.1.0

outputs:
- package:
name: clobber-with-dir
version: 0.1.0

build:
noarch: generic
script:
- mkdir $PREFIX/dir
- echo "clobber-1" > $PREFIX/dir/clobber.txt

- package:
name: clobber-without-dir
version: 0.1.0

build:
noarch: generic
script:
- echo "clobber-1" > $PREFIX/dir
Loading