Skip to content

Commit

Permalink
Improvements on uninstall command error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0der committed May 13, 2023
1 parent 1bbc8b2 commit 4ac75c4
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/bin/uninstall/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,28 @@ fn main() {
let version_path = sdkman_dir.join(&candidate_path).join(&version);
let current_link_path = candidate_path.join(CURRENT_DIR);
if current_link_path.is_dir() {
let canonical_link_path =
fs::read_link(current_link_path.to_owned()).expect("panic! can't read link");
if version_path == canonical_link_path && force {
remove_symlink_dir(current_link_path).expect("panic! can't remove current symlink");
} else if version_path == canonical_link_path && !force {
eprint!(
"\n{} {} is the {} version and should not be removed.",
candidate,
version,
"current".bold(),
);
println!(
"\n\nOverride with {}, but leaves the candidate unusable!",
"--force".italic()
);
process::exit(1);
match fs::read_link(current_link_path.to_owned()) {
Ok(relative_resolved_dir) => {
let resolved_link_path = candidate_path.join(relative_resolved_dir);
if (version_path == resolved_link_path) && force {
remove_symlink_dir(current_link_path).expect("can't remove current symlink");
} else if (version_path == resolved_link_path) && !force {
eprintln!(
"\n{} {} is the {} version and should not be removed.",
candidate.bold(),
version.bold(),
"current".italic(),
);
println!(
"\n\nOverride with {}, but leaves the candidate unusable!",
"--force".italic()
);
process::exit(1);
}
}
Err(e) => {
eprintln!("current link broken, stepping over: {}", e.to_string());
}
}
}

Expand Down

0 comments on commit 4ac75c4

Please sign in to comment.