Skip to content

Commit

Permalink
Merge pull request #67 from iamsauravsharma/prefer-runtime-cargo-home
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsauravsharma authored Feb 20, 2025
2 parents 8586cc9 + a7ca1c9 commit 33c178b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
75 changes: 41 additions & 34 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn clear_empty_index(
})
{
to_remove_indexes.push(index_name);
};
}
}
let mut is_success = true;
for index in to_remove_indexes {
Expand Down Expand Up @@ -602,7 +602,7 @@ fn run_cargo_update_command(cargo_lock_files: &[PathBuf], dry_run: bool) -> Resu
.success()
{
return Err(anyhow::anyhow!("Failed to update {location:?}"));
};
}
}
}
println!("{}", "Successfully updated all dependencies".blue());
Expand Down
11 changes: 10 additions & 1 deletion src/dir_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result};

fn get_cargo_home() -> Result<String> {
if let Ok(cargo_home) = std::env::var("CARGO_HOME") {
return Ok(cargo_home);
}

option_env!("CARGO_HOME")
.map(String::from)
.context("Failed to get CARGO_HOME directory")
}
/// Struct for storing Directory path
pub(crate) struct DirPath {
bin_dir: PathBuf,
Expand Down Expand Up @@ -32,7 +41,7 @@ impl DirPath {
fs::File::create(&config_file).context("failed to create config file")?;
}

let home_dir = Path::new(env!("CARGO_HOME")).to_path_buf();
let home_dir = Path::new(&get_cargo_home()?).to_path_buf();

// set bin directory path
let bin_dir = home_dir.join("bin");
Expand Down
2 changes: 1 addition & 1 deletion src/registry_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn remove_index_cache(path: &Path, crate_metadata: &CrateMetaData, dry_run: bool
crate_index_cache_location.push(&name[2..4]);
crate_index_cache_location.push(name);
}
};
}
delete_folder(&crate_index_cache_location, dry_run)?;
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/command_output.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![expect(unused_crate_dependencies)]
use std::process::{Command, Stdio};

fn run_cargo_trim(args: &[&str]) {
Expand Down

0 comments on commit 33c178b

Please sign in to comment.