Skip to content

Commit

Permalink
Fix dir rename failure
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Feb 11, 2021
1 parent 21eb370 commit 606e081
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 64 deletions.
81 changes: 24 additions & 57 deletions 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
Expand Up @@ -9,7 +9,7 @@ build = "build.rs"
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = { version = "1.0", features = ["derive"] }
zip = "0.5"
zip = { version = "0.5", default-features = false, features = ["deflate"] }

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
Expand Down
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,23 @@ async fn download(client: &Client, url: &str, file: &str) {
}
}

fn get_canonical_path(p: &str) -> String {
let p = Path::new(p).canonicalize().unwrap();
let path = p.to_str().unwrap();
#[cfg(windows)] return format!("{}", &path[4..path.len()]);
#[cfg(unix)] return path.to_string();
}

fn find_java() -> String {
let j = get_canonical_path("java");
#[cfg(target_os = "windows")] {
let java = format!("{}\\bin\\java.exe", Path::new("java").canonicalize().unwrap().to_str().unwrap());
return format!("{}", &java[4..java.len()]);
return format!("{}\\bin\\java.exe", j);;
}
#[cfg(target_os = "linux")] {
return format!("{}/bin/java", fs::canonicalize(Path::new("java")).unwrap().to_str().unwrap());
return format!("{}/bin/java", j);
}
#[cfg(target_os = "macos")] {
return format!("{}/Contents/Home/bin/java", fs::canonicalize(Path::new("java")).unwrap().to_str().unwrap());
return format!("{}/Contents/Home/bin/java", j);
}
}

Expand All @@ -127,6 +134,8 @@ async fn main() {
println!("Licensed under GNU AGPLv3.");
println!("https://github.com/iTXTech/mcl-installer");
println!();
println!("iTXTech MCL will install to {}", get_canonical_path("."));
println!();

let client = reqwest::Client::new();

Expand Down Expand Up @@ -195,8 +204,8 @@ async fn main() {
let end = archive.find(".tar.gz").unwrap();
}

fs::remove_file("java.arc");
fs::rename(java_dir, "java");
fs::remove_file("java.arc").unwrap();
fs::rename(java_dir, "java").unwrap();

break;
}
Expand Down

0 comments on commit 606e081

Please sign in to comment.