Skip to content

Commit

Permalink
configurable global tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr committed Jun 18, 2023
1 parent c9e2d0a commit 37a1a77
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,19 @@ fn main() {
let args = Args::parse();

let global_tempdir = if let Some(ref custom_tempdir_path) = args.global_tempdir_path {
let custom_tmpdir = std::path::PathBuf::from(&custom_tempdir_path);
let mut custom_tmpdir = std::path::PathBuf::from(&custom_tempdir_path);
let dir_display = custom_tmpdir.display();

assert!(
custom_tmpdir.is_dir(),
"global tempdir '{}' not found",
dir_display
);

// otherwise tempdir would be foo.af32ed2 and not foo/af32ed2
custom_tmpdir.push("dir");
let dir_display = custom_tmpdir.display();

TempDir::new_in("icemaker_global_tempdir", &format!("{}", dir_display))
.expect("failed to create global icemaker tempdir")
} else {
Expand All @@ -721,6 +727,8 @@ fn main() {
let global_tempdir_path_closure: PathBuf = global_tempdir.path().to_owned();
let global_tempdir_path: PathBuf = global_tempdir_path_closure.clone();

dbg!(&global_tempdir_path);

println!(
"using {} threads",
if args.threads != 0 {
Expand All @@ -743,6 +751,15 @@ fn main() {
ctrlc::set_handler(move || {
println!("\n\nCtrl+C: TERMINATED\n");

eprintln!("triyng to rm tempdir:");
dbg!(&global_tempdir_path_closure.clone());
if std::fs::remove_dir_all(global_tempdir_path_closure.clone()).is_err() {
eprintln!(
"WARNING: failed to remove global tempdir '{}'",
global_tempdir_path_closure.display()
);
}

ALL_ICES_WITH_FLAGS
.lock()
.unwrap()
Expand All @@ -759,12 +776,6 @@ fn main() {

//dbg!(&global_tempdir_path_closure);

if std::fs::remove_dir_all(global_tempdir_path_closure.clone()).is_err() {
eprintln!(
"WARNING: failed to remove '{}'",
global_tempdir_path_closure.display()
);
}
std::process::exit(42);
})
.expect("Error setting Ctrl-C handler");
Expand Down

0 comments on commit 37a1a77

Please sign in to comment.