initial version

This commit is contained in:
Robin Appelman 2020-07-14 14:57:21 +02:00
commit f64d73e60c
8 changed files with 951 additions and 4 deletions

View file

@ -1,3 +1,46 @@
fn main() {
println!("Hello, world!");
mod backup;
mod store;
use crate::backup::Backup;
use crate::store::Store;
use main_error::MainError;
use md5::Digest;
use std::cmp::max;
use std::collections::HashMap;
use std::path::PathBuf;
use thiserror::Error;
mod api;
#[derive(Debug, Error)]
pub enum Error {
#[error("Request failed: {0}")]
Request(#[from] std::io::Error),
#[error("MD5 digest mismatch for downloaded demo, expected {expected:?}, received {got:?}")]
DigestMismatch { expected: Digest, got: Digest },
}
fn main() -> Result<(), MainError> {
let mut args: HashMap<_, _> = dotenv::vars().collect();
let store = Store::new(args.get("STORAGE_ROOT").expect("no STORAGE_ROOT set"));
let state_path = PathBuf::from(args.remove("STATE_FILE").expect("no STATE_FILE set"));
let backup = Backup::new(store);
let last_page = if state_path.is_file() {
max(
std::fs::read_to_string(&state_path)?
.trim()
.parse::<u32>()?
- 1,
1,
)
} else {
1u32
};
let current_page = backup.backup_from(last_page)?;
std::fs::write(&state_path, format!("{}", current_page))?;
Ok(())
}