mirror of
https://codeberg.org/demostf/backup.git
synced 2026-06-03 09:54:18 +02:00
initial version
This commit is contained in:
parent
10ff2b0339
commit
f64d73e60c
8 changed files with 951 additions and 4 deletions
47
src/main.rs
47
src/main.rs
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue