Skip to content

Commit dd73130

Browse files
committed
ci issue
1 parent d724808 commit dd73130

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

dcspkg/src/commands/install.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use anyhow::{anyhow, bail, Context, Result};
33
use bytes::{Buf, BufMut, BytesMut};
44
use flate2::{read::GzDecoder, CrcReader};
55
use futures_util::StreamExt;
6-
use indicatif::{ProgressBar, ProgressStyle, ProgressState};
7-
use reqwest::get as async_get;
6+
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
87
use reqwest::blocking::get;
8+
use reqwest::get as async_get;
99
use reqwest::{StatusCode, Url};
1010
use std::cmp::min;
1111
use std::fmt::Write;
@@ -119,7 +119,7 @@ fn download_install_file(
119119
//download the package
120120
let response = run_download(pkg_name, &url)?;
121121
log::info!("Finished downloading package...");
122-
122+
123123
//the content of the response
124124
let mut compressed = BytesMut::with_capacity(response.len());
125125
compressed.put(response.as_slice());
@@ -148,20 +148,22 @@ fn download_install_file(
148148
Ok(())
149149
}
150150

151-
152-
fn run_download(pkg_name: &str, url: &Url) -> Result<Vec<u8>>{
151+
fn run_download(pkg_name: &str, url: &Url) -> Result<Vec<u8>> {
153152
//build a single-threaded async runtime
154-
let rt = runtime::Builder::new_current_thread().enable_all().build().context("Failed to build runtime")?;
153+
let rt = runtime::Builder::new_current_thread()
154+
.enable_all()
155+
.build()
156+
.context("Failed to build runtime")?;
155157
//run async download using the runtime
156158
let buffer = rt.block_on(get_package_async(pkg_name, url))?;
157159
Ok(buffer)
158160
}
159161

160-
async fn get_package_async(pkg_name: &str, url: &Url) -> Result<Vec<u8>>{
162+
async fn get_package_async(pkg_name: &str, url: &Url) -> Result<Vec<u8>> {
161163
//make get request
162164
let response = async_get(url.as_ref()).await.context("Request failed")?;
163165
log::info!("Got response from {url}");
164-
166+
165167
if response.status() != StatusCode::OK {
166168
bail!(
167169
"Response was not okay (got code {} when requesting {})",
@@ -170,7 +172,9 @@ async fn get_package_async(pkg_name: &str, url: &Url) -> Result<Vec<u8>>{
170172
)
171173
}
172174

173-
let content_length = response.content_length().context("No content length provided")?;
175+
let content_length = response
176+
.content_length()
177+
.context("No content length provided")?;
174178

175179
//set up progress bar for download
176180
let bar = ProgressBar::new(content_length);
@@ -179,13 +183,13 @@ async fn get_package_async(pkg_name: &str, url: &Url) -> Result<Vec<u8>>{
179183
.with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap())
180184
.progress_chars("=>-"));
181185
bar.set_message(format!("Downloading {}", pkg_name));
182-
186+
183187
//read response body into buffer
184188
let mut downloaded: u64 = 0;
185189
let mut buffer: Vec<u8> = vec![];
186190
let mut stream = response.bytes_stream();
187-
188-
while let Some(item) = stream.next().await{
191+
192+
while let Some(item) = stream.next().await {
189193
let chunk = item.context("Error while downloading package")?;
190194
buffer.extend_from_slice(&chunk);
191195
let new = min(downloaded + (chunk.len() as u64), content_length);
@@ -195,7 +199,6 @@ async fn get_package_async(pkg_name: &str, url: &Url) -> Result<Vec<u8>>{
195199

196200
bar.finish_with_message("Download complete, unpacking...");
197201
Ok(buffer)
198-
199202
}
200203

201204
fn run_install_script(path: &Path) -> Result<()> {

0 commit comments

Comments
 (0)