From cf53190c6f4278060f4e0cde9b9b734b31f1a4b5 Mon Sep 17 00:00:00 2001 From: azomDev Date: Sat, 23 Nov 2024 17:30:53 -0500 Subject: [PATCH] removed curl as system dependency by using minreq --- Cargo.lock | 58 +++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 1 + src/main.rs | 2 +- src/utils/utils.rs | 40 +++++++------------------------- 4 files changed, 65 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa09e03..ca67db5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,6 +605,19 @@ dependencies = [ "adler2", ] +[[package]] +name = "minreq" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" +dependencies = [ + "log", + "once_cell", + "rustls 0.21.12", + "rustls-webpki 0.101.7", + "webpki-roots 0.25.4", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -633,6 +646,7 @@ version = "0.5.0" dependencies = [ "clap", "home", + "minreq", "semver", "serde", "toml", @@ -730,6 +744,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", +] + [[package]] name = "rustls" version = "0.23.16" @@ -740,7 +766,7 @@ dependencies = [ "once_cell", "ring", "rustls-pki-types", - "rustls-webpki", + "rustls-webpki 0.102.8", "subtle", "zeroize", ] @@ -751,6 +777,16 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustls-webpki" version = "0.102.8" @@ -768,6 +804,16 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "semver" version = "1.0.23" @@ -1004,12 +1050,12 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls", + "rustls 0.23.16", "rustls-pki-types", "serde", "serde_json", "url", - "webpki-roots", + "webpki-roots 0.26.6", ] [[package]] @@ -1053,6 +1099,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + [[package]] name = "webpki-roots" version = "0.26.6" diff --git a/Cargo.toml b/Cargo.toml index 5f5587c..4971d00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ path = "src/lib.rs" [dependencies] clap = { version = "4.5.8", features = ["derive"] } home = "0.5.9" +minreq = { version = "2.12.0", features = ["https"] } semver = { version = "1.0.23", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } toml = "0.8.19" diff --git a/src/main.rs b/src/main.rs index 8da05e8..1c950ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,7 @@ fn main() { .get_matches(); - let dependencies = vec!["curl", "tar", "make"]; // todo goal of having no system dependencies + let dependencies = vec!["tar", "make"]; // todo goal of having no system dependencies utils::assert_dependencies(dependencies); utils::assert_global_paths(); utils::clear_temp(); diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 8a0c19c..c3a0f9b 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -108,39 +108,15 @@ pub fn download_file(file_url: &str, file_path: &PathBuf) { } } - match process::Command::new("curl") - .stdin(process::Stdio::null()) - .stdout(process::Stdio::null()) - .stderr(process::Stdio::null()) - .arg("-4") - .arg("-s") - .arg("-o") - .arg(file_path) - .arg("-L") - .arg(file_url) - .status() - { - Ok(status) if status.success() => (), - Ok(_) => abort( - &format!( - "Failed to download file from {} to {}", - file_url, - file_path.display() - ), - None, - ), - Err(e) => abort( - &format!( - "Failed to extract Python version {} to {}", - file_url, - file_path.display() - ), - Some(&e), - ), - } + let request = match minreq::get(file_url).send() { + Ok(res) if (res.status_code == 200) => res, + Ok(_) => abort("todo", None), + Err(e) => abort("todo", Some(&e)), + }; - if !file_path.exists() || !file_path.is_file() { - abort("Downloaded file was not found", None); + match fs::write(file_path, request.as_bytes()) { + Ok(()) => (), + Err(e) => abort("todo", Some(&e)), } }