mirror of
https://github.com/lights0123/n-link.git
synced 2024-12-22 18:25:27 +00:00
Added error handling to upload
subcommand
This commit is contained in:
parent
a08eb0b791
commit
fd6d7d87b6
|
@ -100,17 +100,25 @@ pub fn run() -> bool {
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
let bar = ProgressBar::new(buf.len() as u64);
|
let bar = ProgressBar::new(buf.len() as u64);
|
||||||
bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg}[{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})"));
|
bar.set_style(ProgressStyle::default_bar().template("{spinner:.green} {msg} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})"));
|
||||||
bar.set_message(&format!("Upload {}", name));
|
bar.set_message(&format!("Upload {}", name));
|
||||||
bar.enable_steady_tick(100);
|
bar.enable_steady_tick(100);
|
||||||
if dest.ends_with('/') {
|
if dest.ends_with('/') {
|
||||||
dest.remove(dest.len() - 1);
|
dest.remove(dest.len() - 1);
|
||||||
}
|
}
|
||||||
handle
|
let res = handle
|
||||||
.write_file(&format!("{}/{}", dest, name), &buf, &mut |remaining| {
|
.write_file(&format!("{}/{}", dest, name), &buf, &mut |remaining| {
|
||||||
bar.set_position((buf.len() - remaining) as u64)
|
bar.set_position((buf.len() - remaining) as u64)
|
||||||
})
|
});
|
||||||
.unwrap();
|
|
||||||
|
match res {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Upload {}: Ok", dest);
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
bar.abandon_with_message(&format!("Failed: {}", error));
|
||||||
|
}
|
||||||
|
}
|
||||||
bar.finish();
|
bar.finish();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue