Reduced panics
This commit is contained in:
parent
182442ba3b
commit
36ad1263b4
@ -28,9 +28,7 @@ pub enum DlStatus {
|
||||
DoneErr {
|
||||
filename: String
|
||||
},
|
||||
Message(String),
|
||||
/// Like Message but triggers a display refresh
|
||||
MessageNow(String)
|
||||
Message(String)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -53,13 +51,14 @@ impl DlReporter {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send(& self, status: DlStatus) -> ResBE<()> {
|
||||
pub fn send(& self, status: DlStatus) {
|
||||
// This should not fail, so unwrap it here instead propagating the error
|
||||
self.transmitter.send(
|
||||
DlReport {
|
||||
id: self.id,
|
||||
status: status
|
||||
}
|
||||
).map_err(|e| e.into())
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,9 +214,6 @@ pub async fn watch_and_print_reports(mut receiver: mpsc::UnboundedReceiver<DlRep
|
||||
},
|
||||
DlStatus::Message(msg) => {
|
||||
msg_queue.push_back(msg);
|
||||
},
|
||||
DlStatus::MessageNow(msg) => {
|
||||
msg_queue.push_back(msg);
|
||||
moved_lines = print_accumulated_report(&statuses, &mut msg_queue, moved_lines)?;
|
||||
t_last = SystemTime::now();
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ pub async fn download_feedback_chunks(url: &str, into_file: &str, rep: DlReporte
|
||||
bytes_total: content_length,
|
||||
filename: filename.to_string()
|
||||
}
|
||||
)?;
|
||||
);
|
||||
|
||||
|
||||
let mut curr_progress = 0;
|
||||
@ -184,7 +184,7 @@ pub async fn download_feedback_chunks(url: &str, into_file: &str, rep: DlReporte
|
||||
speed_mbps: speed_mbps,
|
||||
bytes_curr: curr_progress
|
||||
}
|
||||
)?;
|
||||
);
|
||||
}
|
||||
|
||||
if buff.len() > 0 {
|
||||
@ -201,7 +201,7 @@ pub async fn download_feedback_chunks(url: &str, into_file: &str, rep: DlReporte
|
||||
DlStatus::Done {
|
||||
duration_ms: duration_ms
|
||||
}
|
||||
)?;
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -255,7 +255,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
rep.send(DlStatus::Init {
|
||||
bytes_total: content_length,
|
||||
filename: into_file.to_string()
|
||||
})?;
|
||||
});
|
||||
|
||||
let rep_task = rep.clone();
|
||||
|
||||
@ -292,7 +292,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
rep.send(DlStatus::Update {
|
||||
speed_mbps: speed,
|
||||
bytes_curr: curr
|
||||
}).unwrap();
|
||||
});
|
||||
|
||||
} else {
|
||||
update_counter += 1;
|
||||
@ -308,7 +308,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
},
|
||||
|
||||
// Just forwared everything else to the calling receiver
|
||||
_ => rep.send(update.status).unwrap()
|
||||
_ => rep.send(update.status)
|
||||
|
||||
}
|
||||
}
|
||||
@ -348,7 +348,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
|
||||
rep.send(DlStatus::Done {
|
||||
duration_ms: t_start.elapsed()?.as_millis() as u64
|
||||
})?;
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
50
src/main.rs
50
src/main.rs
@ -88,8 +88,6 @@ async fn main() -> ResBE<()> {
|
||||
.get_matches();
|
||||
|
||||
|
||||
|
||||
|
||||
let outdir = match arguments.value_of("outdir") {
|
||||
Some(it) => it,
|
||||
None => "./"
|
||||
@ -133,9 +131,11 @@ async fn main() -> ResBE<()> {
|
||||
|
||||
let is_zippy = arguments.is_present("zippyshare");
|
||||
|
||||
if arguments.is_present("listfile") {
|
||||
|
||||
let s_listfile = arguments.value_of("listfile").unwrap();
|
||||
// Evaluate and execute the requested action. The 3 different actions are
|
||||
// mutally exclusive, so only one of them will be executed
|
||||
|
||||
if let Some(s_listfile) = arguments.value_of("listfile") {
|
||||
|
||||
let listfile = Path::new(s_listfile);
|
||||
|
||||
@ -154,29 +154,28 @@ async fn main() -> ResBE<()> {
|
||||
|
||||
download_multiple(urls, outdir, numparal, boost, is_zippy).await?;
|
||||
|
||||
} else if arguments.is_present("download") {
|
||||
}
|
||||
|
||||
if let Some(url) = arguments.value_of("download") {
|
||||
|
||||
let url = arguments.value_of("download").unwrap();
|
||||
|
||||
let numparal = if boost != 1 {
|
||||
let boost = if boost != 1 {
|
||||
boost
|
||||
} else {
|
||||
numparal
|
||||
};
|
||||
|
||||
download_multiple(vec![url.to_string()], outdir, 1, numparal, is_zippy).await?;
|
||||
download_multiple(vec![url.to_string()], outdir, 1, boost, is_zippy).await?;
|
||||
|
||||
} else if arguments.is_present("resolve") {
|
||||
|
||||
let url = arguments.value_of("resolve").unwrap();
|
||||
}
|
||||
|
||||
if let Some(url) = arguments.value_of("resolve") {
|
||||
|
||||
match zippy::resolve_link(&url).await {
|
||||
Ok(resolved_url) => {
|
||||
println!("{}", resolved_url);
|
||||
},
|
||||
Err(e) => {
|
||||
Err(_e) => {
|
||||
println!("Zippyshare link could not be resolved");
|
||||
eprintln!("{}", e);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -233,8 +232,8 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, numparal: i32, boost
|
||||
Ok(url) => url,
|
||||
Err(_e) => {
|
||||
rep.send(
|
||||
DlStatus::MessageNow(format!("Zippyshare link could not be resolved: {}", url))
|
||||
).unwrap();
|
||||
DlStatus::Message(format!("Zippyshare link could not be resolved: {}", url))
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -250,14 +249,23 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, numparal: i32, boost
|
||||
|
||||
// If file with same name is present locally, check filesize
|
||||
if path_into_file.exists() {
|
||||
let (filesize, _) = download::http_get_filesize_and_range_support(&url).await.unwrap();
|
||||
let filesize = match download::http_get_filesize_and_range_support(&url).await {
|
||||
Ok((filesize, _)) => filesize,
|
||||
Err(_e) => {
|
||||
rep.send(
|
||||
DlStatus::Message(format!("Error while querying metadata: {}", url))
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let local_filesize = std::fs::metadata(path_into_file).unwrap().len();
|
||||
|
||||
if filesize == local_filesize {
|
||||
rep.send(DlStatus::MessageNow(format!("Skipping file '{}': already present", &file_name))).unwrap();
|
||||
rep.send(DlStatus::Message(format!("Skipping file '{}': already present", &file_name)));
|
||||
continue;
|
||||
} else {
|
||||
rep.send(DlStatus::MessageNow(format!("Replacing file '{}': present but not completed", &file_name))).unwrap();
|
||||
rep.send(DlStatus::Message(format!("Replacing file '{}': present but not completed", &file_name)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,13 +273,13 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, numparal: i32, boost
|
||||
if let Err(_e) = download::download_feedback(&url, &into_file, rep.clone()).await {
|
||||
rep.send(DlStatus::DoneErr {
|
||||
filename: into_file.to_string()
|
||||
}).unwrap();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if let Err(_e) = download::download_feedback_multi(&url, &into_file, rep.clone(), boost).await {
|
||||
rep.send(DlStatus::DoneErr {
|
||||
filename: into_file.to_string()
|
||||
}).unwrap();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user