minor cleanups

This commit is contained in:
Jörn-Michael Miehe 2025-06-13 23:11:40 +00:00
parent 876869b073
commit 5b018cf84b
2 changed files with 13 additions and 14 deletions

View file

@ -46,18 +46,15 @@ impl Uploading {
}
pub fn rewind(self) -> Option<Self> {
match self.last_offset {
Some(last_offset) => Some(Self {
if let Some(last_offset) = self.last_offset { Some(Self {
last_offset: None,
offset: last_offset,
..self
}),
None => {
}) } else {
warn!("attempted to rewind twice");
None
}
}
}
pub fn read<'t>(&mut self, buf: &'t mut [u8]) -> io::Result<Chunk<'t>> {
let mut f = fs::File::open(&self.path)?;

View file

@ -15,7 +15,7 @@ use std::{
use clap::Parser;
use console::style;
use dialoguer::{Confirm, theme::ColorfulTheme};
use log::{error, info};
use log::{error, info, trace};
use appstate::AppState;
use cli::Cli;
@ -118,7 +118,7 @@ fn main() {
loop {
match state.upload_chunk(&mut buffer) {
Err(e) => {
// HACK handle errors better
// HACK handle errors better (this will just retry endlessly)
error!("error: {e:?}");
if let Some(s) = state.rewind() {
@ -126,13 +126,15 @@ fn main() {
} else {
eprintln!("{} Failed to retry chunk!", style("Error:").red().bold());
process::exit(1);
};
}
}
Ok(false) => {
trace!("chunk uploaded");
}
Ok(true) => {
info!("all uploads done");
break;
}
_ => (),
}
state.save().unwrap_or_else(|e| {