Skip to content

Commit

Permalink
removed curl as system dependency by using minreq
Browse files Browse the repository at this point in the history
  • Loading branch information
azomDev committed Nov 26, 2024
1 parent 5a74e8f commit cf53190
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 36 deletions.
58 changes: 55 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
40 changes: 8 additions & 32 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand Down

0 comments on commit cf53190

Please sign in to comment.