[wip] retry chunks
- `AppState::rewind` impl - error handling in `main`
This commit is contained in:
parent
0a8e5cf3f0
commit
30855ed8ff
3 changed files with 36 additions and 7 deletions
|
|
@ -11,7 +11,7 @@ use log::{debug, warn};
|
|||
use super::{
|
||||
cachefile::CacheFile,
|
||||
cli::Cli,
|
||||
file::{self, FileTrait, Chunk},
|
||||
file::{self, Chunk, FileTrait},
|
||||
sharry::{self, Client},
|
||||
};
|
||||
|
||||
|
|
@ -162,6 +162,18 @@ impl AppState {
|
|||
Ok(self.is_done())
|
||||
}
|
||||
|
||||
pub fn rewind(mut self) -> Option<Self> {
|
||||
let Some(uploading) = self.inner.pop_file(&self.http) else {
|
||||
warn!("rewind called on empty queue");
|
||||
return None;
|
||||
};
|
||||
|
||||
let uploading = uploading.rewind()?;
|
||||
self.inner.push_file(uploading);
|
||||
|
||||
Some(self)
|
||||
}
|
||||
|
||||
pub fn file_names(&self) -> Vec<&str> {
|
||||
self.inner.file_names()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
path::PathBuf,
|
||||
};
|
||||
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Chunk, FileTrait};
|
||||
|
|
@ -45,11 +46,17 @@ impl Uploading {
|
|||
}
|
||||
|
||||
pub fn rewind(self) -> Option<Self> {
|
||||
self.last_offset.map(|last_offset| Self {
|
||||
last_offset: None,
|
||||
offset: last_offset,
|
||||
..self
|
||||
})
|
||||
match self.last_offset {
|
||||
Some(last_offset) => Some(Self {
|
||||
last_offset: None,
|
||||
offset: last_offset,
|
||||
..self
|
||||
}),
|
||||
None => {
|
||||
warn!("attempted to rewind twice");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<'t>(&mut self, buf: &'t mut [u8]) -> io::Result<Chunk<'t>> {
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -117,7 +117,17 @@ fn main() {
|
|||
|
||||
loop {
|
||||
match state.upload_chunk(&mut buffer) {
|
||||
Err(e) => error!("error: {e:?}"), // HACK handle errors better
|
||||
Err(e) => {
|
||||
// HACK handle errors better
|
||||
error!("error: {e:?}");
|
||||
|
||||
if let Some(s) = state.rewind() {
|
||||
state = s;
|
||||
} else {
|
||||
eprintln!("{} Failed to retry chunk!", style("Error:").red().bold());
|
||||
process::exit(1);
|
||||
};
|
||||
}
|
||||
Ok(true) => {
|
||||
info!("all uploads done");
|
||||
state.clear().unwrap_or_else(|e| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue