Skip to content

Commit

Permalink
Resort to string concatenation for cygwin.
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0der committed May 8, 2023
1 parent 560b156 commit 3d35adc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 12 additions & 12 deletions src/bin/uninstall/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ fn main() {
process::exit(1);
}

let candidate_path = sdkman_dir
.to_owned()
.join(CANDIDATES_DIR)
.join(candidate.to_owned());
let candidate_version_path = candidate_path.join(version.to_owned());
let current_link_path = candidate_path.join(CURRENT_DIR);
let inferred_dir = infer_sdkman_dir();
let sdkman_dir = inferred_dir.to_str().unwrap();

let candidate_dir = format!("{}/{}/{}", sdkman_dir, CANDIDATES_DIR, candidate);
let version_dir = format!("{}/{}", candidate_dir, version);
let version_path = PathBuf::from(version_dir);
let current_link_path = PathBuf::from(format!("{}/{}", candidate_dir, CURRENT_DIR));
if current_link_path.is_dir() {
let read_link =
let canonical_link_path =
fs::read_link(current_link_path.to_owned()).expect("panic! can't read link");
let canonical_link = candidate_path.join(read_link);
if candidate_version_path == canonical_link && force {
if version_path == canonical_link_path && force {
remove_symlink_dir(current_link_path).expect("panic! can't remove current symlink");
} else if candidate_version_path == canonical_link && !force {
} else if version_path == canonical_link_path && !force {
eprint!(
"\n{} {} is the {} version and should not be removed.",
candidate,
Expand All @@ -65,8 +65,8 @@ fn main() {
}
}

if candidate_version_path.is_dir() {
fs::remove_dir_all(candidate_version_path).expect("panic! could not delete directory");
if version_path.is_dir() {
fs::remove_dir_all(version_path).expect("panic! could not delete directory");
println!("removed {} {}", candidate.bold(), version.bold());
} else {
eprintln!(
Expand Down
24 changes: 14 additions & 10 deletions src/bin/version/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ use sdkman_cli_native::{
constants::VAR_DIR,
helpers::{infer_sdkman_dir, read_file_content},
};
use std::path::PathBuf;

const CLI_VERSION_FILE: &str = "version";
const NATIVE_VERSION_FILE: &str = "version_native";

fn main() {
let sdkman_dir = infer_sdkman_dir();
let var_dir = sdkman_dir.join(VAR_DIR);
let inferred_dir = infer_sdkman_dir();
let sdkman_dir = inferred_dir.to_str().unwrap();

let cli_version_file = var_dir.join(CLI_VERSION_FILE);
let native_version_file = var_dir.join(NATIVE_VERSION_FILE);

let absolute_cli_version = verify_absolute_path(cli_version_file);
let cli_version = read_file_content(absolute_cli_version);

let absolute_native_version = verify_absolute_path(native_version_file);
let native_version = read_file_content(absolute_native_version);
let cli_version = read_version_file(format!("{}/{}/{}", sdkman_dir, VAR_DIR, CLI_VERSION_FILE));
let native_version = read_version_file(format!(
"{}/{}/{}",
sdkman_dir, VAR_DIR, NATIVE_VERSION_FILE
));

match (cli_version, native_version) {
(Some(cli), Some(native)) => println!(
Expand All @@ -33,3 +31,9 @@ fn main() {
_ => std::process::exit(exitcode::CONFIG),
}
}

fn read_version_file(file_location: String) -> Option<String> {
let version_path = PathBuf::from(file_location);
let verified_path = verify_absolute_path(version_path);
read_file_content(verified_path)
}

0 comments on commit 3d35adc

Please sign in to comment.