Skip to content

Commit

Permalink
fix: Fix leaking package cache directory (#47)
Browse files Browse the repository at this point in the history
* fix: Fix leaking package cache directory

* Bump version

* Check for errors when removing temp dir
  • Loading branch information
delsner authored Aug 19, 2024
1 parent 924d518 commit 98a5d43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pixi-pack"
description = "A command line tool to pack and unpack conda environments for easy sharing"
version = "0.1.7"
version = "0.1.8"
edition = "2021"

[features]
Expand Down
20 changes: 11 additions & 9 deletions src/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {
let tmp_dir =
tempfile::tempdir().map_err(|e| anyhow!("Could not create temporary directory: {}", e))?;
let unpack_dir = tmp_dir.path();
let channel_directory = unpack_dir.join(CHANNEL_DIRECTORY_NAME);

tracing::info!("Unarchiving pack to {}", unpack_dir.display());
unarchive(&options.pack_file, unpack_dir)
Expand All @@ -51,7 +50,9 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {
let target_prefix = options.output_directory.join("env");

tracing::info!("Creating prefix at {}", target_prefix.display());
create_prefix(&channel_directory, &target_prefix)
let channel_directory = unpack_dir.join(CHANNEL_DIRECTORY_NAME);
let cache_dir = unpack_dir.join("cache");
create_prefix(&channel_directory, &target_prefix, &cache_dir)
.await
.map_err(|e| anyhow!("Could not create prefix: {}", e))?;

Expand All @@ -73,6 +74,10 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {
options.output_directory.display()
);

tmp_dir
.close()
.map_err(|e| anyhow!("Could not remove temporary directory: {}", e))?;

Ok(())
}

Expand Down Expand Up @@ -158,18 +163,15 @@ pub async fn unarchive(archive_path: &Path, target_dir: &Path) -> Result<()> {
Ok(())
}

async fn create_prefix(channel_dir: &Path, target_prefix: &Path) -> Result<()> {
async fn create_prefix(channel_dir: &Path, target_prefix: &Path, cache_dir: &Path) -> Result<()> {
let packages = collect_packages(channel_dir)
.await
.map_err(|e| anyhow!("could not collect packages: {}", e))?;

let cache_dir = tempfile::tempdir()
.map_err(|e| anyhow!("could not create temporary directory: {}", e))?
.into_path();

eprintln!(
"⏳ Extracting and installing {} packages...",
packages.len()
"⏳ Extracting and installing {} packages to {}...",
packages.len(),
cache_dir.display()
);
let reporter = ProgressReporter::new(packages.len() as u64);

Expand Down

0 comments on commit 98a5d43

Please sign in to comment.