refactor: add Justfile; fix some clippy lints
parent
abafd9a28c
commit
08e77034a7
|
@ -0,0 +1,35 @@
|
||||||
|
[group('build')]
|
||||||
|
build pkg:
|
||||||
|
cargo build --package {{ pkg }}
|
||||||
|
alias b := build
|
||||||
|
|
||||||
|
[group('build')]
|
||||||
|
build-all:
|
||||||
|
cargo build --workspace
|
||||||
|
alias ba := build-all
|
||||||
|
|
||||||
|
[group('test')]
|
||||||
|
test pkg:
|
||||||
|
cargo test --package {{ pkg }}
|
||||||
|
alias t := test
|
||||||
|
|
||||||
|
[group('test')]
|
||||||
|
test-all:
|
||||||
|
cargo test --workspace
|
||||||
|
alias ta := test-all
|
||||||
|
|
||||||
|
[group('check')]
|
||||||
|
check pkg:
|
||||||
|
cargo fmt --check --package {{ pkg }}
|
||||||
|
cargo clippy --package {{ pkg }} -- \
|
||||||
|
--no-deps \
|
||||||
|
--deny 'clippy::all'
|
||||||
|
alias c := check
|
||||||
|
|
||||||
|
[group('check')]
|
||||||
|
check-all:
|
||||||
|
cargo fmt --check --all
|
||||||
|
cargo clippy --all -- \
|
||||||
|
--no-deps \
|
||||||
|
--deny 'clippy::all'
|
||||||
|
alias ca := check-all
|
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use super::State;
|
use super::State;
|
||||||
|
|
||||||
/// Represents the changes relative to the previous backup
|
/// Represents the changes relative to the previous backup
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
pub struct Delta {
|
pub struct Delta {
|
||||||
/// What files were added/modified in each part of the tarball.
|
/// What files were added/modified in each part of the tarball.
|
||||||
pub added: State,
|
pub added: State,
|
||||||
|
@ -17,13 +17,6 @@ pub struct Delta {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Delta {
|
impl Delta {
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
added: State::new(),
|
|
||||||
removed: State::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether the delta is empty by checking whether both its added and removed state
|
/// Returns whether the delta is empty by checking whether both its added and removed state
|
||||||
/// return true for their `is_empty`.
|
/// return true for their `is_empty`.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl<T: Clone> Backup<T> {
|
||||||
let enc = GzEncoder::new(tar_gz, Compression::default());
|
let enc = GzEncoder::new(tar_gz, Compression::default());
|
||||||
let mut ar = tar::Builder::new(enc);
|
let mut ar = tar::Builder::new(enc);
|
||||||
|
|
||||||
let mut delta = Delta::new();
|
let mut delta = Delta::default();
|
||||||
|
|
||||||
for (dir_in_tar, src_dir) in dirs {
|
for (dir_in_tar, src_dir) in dirs {
|
||||||
let mut added_files: HashSet<PathBuf> = HashSet::new();
|
let mut added_files: HashSet<PathBuf> = HashSet::new();
|
||||||
|
@ -187,7 +187,7 @@ impl<T: Clone> Backup<T> {
|
||||||
let enc = GzEncoder::new(tar_gz, Compression::default());
|
let enc = GzEncoder::new(tar_gz, Compression::default());
|
||||||
let mut ar = tar::Builder::new(enc);
|
let mut ar = tar::Builder::new(enc);
|
||||||
|
|
||||||
let mut delta = Delta::new();
|
let mut delta = Delta::default();
|
||||||
|
|
||||||
for (dir_in_tar, src_dir) in dirs {
|
for (dir_in_tar, src_dir) in dirs {
|
||||||
let mut all_files: HashSet<PathBuf> = HashSet::new();
|
let mut all_files: HashSet<PathBuf> = HashSet::new();
|
||||||
|
|
|
@ -11,14 +11,10 @@ use crate::Delta;
|
||||||
|
|
||||||
/// Struct that represents a current state for a backup. This struct acts as a smart pointer around
|
/// Struct that represents a current state for a backup. This struct acts as a smart pointer around
|
||||||
/// a HashMap.
|
/// a HashMap.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||||
pub struct State(HashMap<PathBuf, HashSet<PathBuf>>);
|
pub struct State(HashMap<PathBuf, HashSet<PathBuf>>);
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new() -> Self {
|
|
||||||
State(HashMap::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Apply the delta to the current state.
|
/// Apply the delta to the current state.
|
||||||
pub fn apply(&mut self, delta: &Delta) {
|
pub fn apply(&mut self, delta: &Delta) {
|
||||||
// First we add new files, then we remove the old ones
|
// First we add new files, then we remove the old ones
|
||||||
|
@ -61,7 +57,7 @@ where
|
||||||
T::Item: Borrow<Delta>,
|
T::Item: Borrow<Delta>,
|
||||||
{
|
{
|
||||||
fn from(deltas: T) -> Self {
|
fn from(deltas: T) -> Self {
|
||||||
let mut state = State::new();
|
let mut state = State::default();
|
||||||
|
|
||||||
for delta in deltas {
|
for delta in deltas {
|
||||||
state.apply(delta.borrow());
|
state.apply(delta.borrow());
|
||||||
|
@ -90,9 +86,3 @@ impl DerefMut for State {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue