1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! # Directory Signature Library
//!
//! ## v1
//!
//! Currently we have only implemented `v1` version of signature file,
//! it has the following limitations:
//!
//! * Only stores executable bit for files, no permissions and ownership
//!   support (this also means files can be replicated without privileges)
//! * File modification times are not checked and not replicated
//! * It's ascii text, so potentially 2x larger than what binary file could be
//!
//! While these limitations are not enough for generic backup purposes they
//! are fine for deploying configs and read-only images to production servers
//! in 99% use cases. Latter was a primary use case for the library. We will
//! probably make a more featureful format as v2 and later as deemed necessary.
//!
//! Design of the format features the following things:
//!
//! * Reproducible (does not depend on order of file scan)
//! * Easy to check even using a bash script (sans edge cases)
//! * Usable for file synchronization
//! * Can be produced and checked without loading full index into memory
//!
#![warn(missing_docs)]
#![recursion_limit="100"]

extern crate openat;
extern crate sha2;
extern crate blake2;
extern crate digest_writer;
extern crate generic_array;
extern crate itertools;
#[macro_use] extern crate log;
#[macro_use] extern crate quick_error;

#[cfg(feature="threads")] extern crate num_cpus;
#[cfg(feature="threads")] extern crate futures;
#[cfg(feature="threads")] extern crate futures_cpupool;
#[cfg(test)] #[macro_use] extern crate pretty_assertions;

#[cfg(test)]
#[macro_use] extern crate matches;
#[cfg(test)]
extern crate rustc_hex;


pub mod v1;
mod error;
mod config;
mod hash_type;
mod read;

pub use error::Error;
pub use read::get_hash;

use std::path::PathBuf;

/// Scanner config contains a list of directories you will scan and other
/// settings that influence filesystem scanning
pub struct ScannerConfig {
    threads: usize,
    queue_size: Option<usize>,
    hash: HashType,
    block_size: u64,
    dirs: Vec<(PathBuf, PathBuf)>,
    print_progress: bool,
}

/// A type of hash supported by the library
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct HashType(HashTypeEnum);

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types)]
enum HashTypeEnum {
    Sha512_256,
    Blake2b_256,
}