Compare commits

..

No commits in common. "dea6108b8ec5f9196d8698fe2821d1d4c291cce1" and "666aae5a4659fa270403d85b7535f90280ba9307" have entirely different histories.

3 changed files with 17 additions and 21 deletions

View file

@ -5,7 +5,7 @@ use std::{
path::{Path, PathBuf},
};
use log::{debug, trace};
use log::{debug, error, trace};
use serde::{Deserialize, Serialize};
use super::{
@ -35,14 +35,14 @@ impl AppState {
.expect("could not determine cache directory")
.join("shrupl");
trace!("cachedir: {:?}", dir_name.display());
trace!("cachedir: {}", dir_name.display());
dir_name
}
fn cache_file(args: &Cli) -> PathBuf {
let file_name = Self::cache_dir().join(format!("{}.json", args.get_hash()));
trace!("cachefile: {:?}", file_name.display());
trace!("cachefile: {}", file_name.display());
file_name
}
@ -55,7 +55,7 @@ impl AppState {
let file_name = Self::cache_file(args);
Self::load(&file_name)
.inspect_err(|e| debug!("could not resume from {:?}: {e}", file_name.display()))
.inspect_err(|e| debug!("could not resume from {}: {e}", file_name.display()))
.map(|state| {
debug!("successfully loaded AppState");
@ -69,16 +69,17 @@ impl AppState {
.ok()
}
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Result<Self, String> {
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Option<Self> {
let file_name = Self::cache_file(args);
let alias = args.get_alias();
let share = Share::create(http, &alias, args.get_share_request())
.map_err(|e| format!("could not create share: {e}"))?;
.inspect_err(|e| error!("could not create Share: {e}"))
.ok()?;
let files: VecDeque<_> = args.files.clone().into_iter().map(FileState::C).collect();
Ok(Self {
Some(Self {
file_name,
alias,
share,

View file

@ -2,12 +2,9 @@ mod appstate;
mod cli;
mod sharry;
use std::{
process::exit,
sync::{
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
},
};
use clap::Parser;
@ -41,11 +38,11 @@ fn main() {
state
})
.or_else(|| AppState::from_args(&args, &agent))
.unwrap_or_else(|| {
AppState::from_args(&args, &agent).unwrap_or_else(|e| {
error!("could not create new state: {e}");
exit(1);
})
error!("could not create new state from cli arguments: {args:?}");
std::process::exit(1);
});
info!("continuing with state: {state:?}");
@ -62,7 +59,7 @@ fn main() {
if !running.load(Ordering::SeqCst) {
info!("terminating ...");
exit(0);
std::process::exit(0);
}
}

View file

@ -41,9 +41,7 @@ impl Display for FileUploading {
write!(
f,
"Uploading ({:?}, {}, {})",
self.path.display(),
self.size,
self.offset
self.path, self.size, self.offset
)
}
}