This commit is contained in:
Michael Zhang 2023-06-13 05:47:04 -05:00
commit f1e5d370d3
9 changed files with 1970 additions and 0 deletions

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[registries.crates-io]
protocol = "sparse"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1868
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

15
Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
name = "upback"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.71"
clap = { version = "4.3.3", features = ["derive"] }
dirs = "5.0.1"
serde = { version = "1.0.164", features = ["derive"] }
serde_yaml = "0.9.21"
tokio = { version = "1.28.2", features = ["full"] }
twelf = { version = "0.11.0", features = ["json", "yaml", "toml", "dhall"] }

2
config.yml Normal file
View file

@ -0,0 +1,2 @@
directories:
/Users/michaelzhang/tmp/upback:

4
rustfmt.toml Normal file
View file

@ -0,0 +1,4 @@
max_width = 80
tab_spaces = 2
wrap_comments = true
fn_single_line = true

39
src/config.rs Normal file
View file

@ -0,0 +1,39 @@
use std::{collections::HashMap, path::PathBuf};
use twelf::config;
#[derive(Debug, Serialize)]
#[config]
pub struct Config {
#[serde(default)]
directories: HashMap<PathBuf, PathBackupConfig>,
}
#[derive(Debug, Serialize)]
#[config]
pub struct PathBackupConfig {
#[serde(default)]
update_check_strategy: Option<UpdateCheckStrategy>,
#[serde(default)]
subpaths: HashMap<PathBuf, PathBackupConfig>,
}
#[derive(Debug, Serialize)]
#[config]
pub struct DestinationConfig {
backend: DestinationBackend,
}
#[derive(Default, Debug, Serialize, Deserialize)]
pub enum UpdateCheckStrategy {
/// Just check atime + file size
#[default]
AtimeFileSize,
/// Calculate a 128-bit checksum (slow)
Checksum,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum DestinationBackend {}

25
src/main.rs Normal file
View file

@ -0,0 +1,25 @@
pub mod config;
pub mod patterns;
#[macro_use]
extern crate serde;
use std::{fs::File, io::Read};
use anyhow::Result;
use crate::config::Config;
#[tokio::main]
async fn main() -> Result<()> {
println!("Hello, world!");
let config: Config = {
let file = File::open("config.yml")?;
serde_yaml::from_reader(file)?
};
println!("config: {config:?}");
Ok(())
}

14
src/patterns.rs Normal file
View file

@ -0,0 +1,14 @@
use std::path::PathBuf;
pub struct Pattern {
pub found_at: PathBuf,
pub kind: PatternKind,
}
pub enum PatternKind {
/// Just a plain ol' file. Read + write
Regular,
/// Archives can probably be diffed granularly? Maybe above a certain file size
Archive,
}