Compare commits
3 commits
666aae5a46
...
dea6108b8e
| Author | SHA1 | Date | |
|---|---|---|---|
| dea6108b8e | |||
| e7f0fc5a38 | |||
| 7e9d553ef8 |
3 changed files with 21 additions and 17 deletions
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::{debug, error, trace};
|
use log::{debug, trace};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|
@ -35,14 +35,14 @@ impl AppState {
|
||||||
.expect("could not determine cache directory")
|
.expect("could not determine cache directory")
|
||||||
.join("shrupl");
|
.join("shrupl");
|
||||||
|
|
||||||
trace!("cachedir: {}", dir_name.display());
|
trace!("cachedir: {:?}", dir_name.display());
|
||||||
dir_name
|
dir_name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cache_file(args: &Cli) -> PathBuf {
|
fn cache_file(args: &Cli) -> PathBuf {
|
||||||
let file_name = Self::cache_dir().join(format!("{}.json", args.get_hash()));
|
let file_name = Self::cache_dir().join(format!("{}.json", args.get_hash()));
|
||||||
|
|
||||||
trace!("cachefile: {}", file_name.display());
|
trace!("cachefile: {:?}", file_name.display());
|
||||||
file_name
|
file_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl AppState {
|
||||||
let file_name = Self::cache_file(args);
|
let file_name = Self::cache_file(args);
|
||||||
|
|
||||||
Self::load(&file_name)
|
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| {
|
.map(|state| {
|
||||||
debug!("successfully loaded AppState");
|
debug!("successfully loaded AppState");
|
||||||
|
|
||||||
|
|
@ -69,17 +69,16 @@ impl AppState {
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Option<Self> {
|
pub fn from_args(args: &Cli, http: &ureq::Agent) -> Result<Self, String> {
|
||||||
let file_name = Self::cache_file(args);
|
let file_name = Self::cache_file(args);
|
||||||
let alias = args.get_alias();
|
let alias = args.get_alias();
|
||||||
|
|
||||||
let share = Share::create(http, &alias, args.get_share_request())
|
let share = Share::create(http, &alias, args.get_share_request())
|
||||||
.inspect_err(|e| error!("could not create Share: {e}"))
|
.map_err(|e| format!("could not create share: {e}"))?;
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let files: VecDeque<_> = args.files.clone().into_iter().map(FileState::C).collect();
|
let files: VecDeque<_> = args.files.clone().into_iter().map(FileState::C).collect();
|
||||||
|
|
||||||
Some(Self {
|
Ok(Self {
|
||||||
file_name,
|
file_name,
|
||||||
alias,
|
alias,
|
||||||
share,
|
share,
|
||||||
|
|
|
||||||
19
src/main.rs
19
src/main.rs
|
|
@ -2,9 +2,12 @@ mod appstate;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod sharry;
|
mod sharry;
|
||||||
|
|
||||||
use std::sync::{
|
use std::{
|
||||||
Arc,
|
process::exit,
|
||||||
atomic::{AtomicBool, Ordering},
|
sync::{
|
||||||
|
Arc,
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
@ -38,11 +41,11 @@ fn main() {
|
||||||
|
|
||||||
state
|
state
|
||||||
})
|
})
|
||||||
.or_else(|| AppState::from_args(&args, &agent))
|
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
error!("could not create new state from cli arguments: {args:?}");
|
AppState::from_args(&args, &agent).unwrap_or_else(|e| {
|
||||||
|
error!("could not create new state: {e}");
|
||||||
std::process::exit(1);
|
exit(1);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
info!("continuing with state: {state:?}");
|
info!("continuing with state: {state:?}");
|
||||||
|
|
@ -59,7 +62,7 @@ fn main() {
|
||||||
|
|
||||||
if !running.load(Ordering::SeqCst) {
|
if !running.load(Ordering::SeqCst) {
|
||||||
info!("terminating ...");
|
info!("terminating ...");
|
||||||
std::process::exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ impl Display for FileUploading {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Uploading ({:?}, {}, {})",
|
"Uploading ({:?}, {}, {})",
|
||||||
self.path, self.size, self.offset
|
self.path.display(),
|
||||||
|
self.size,
|
||||||
|
self.offset
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue