conserve/
lib.rs

1// Copyright 2015-2023 Martin Pool.
2
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12
13//! Conserve backup system.
14
15pub mod apath;
16pub mod archive;
17pub mod backup;
18mod band;
19pub mod bandid;
20pub mod blockdir;
21pub mod blockhash;
22pub mod change;
23pub mod compress;
24pub mod counters;
25mod diff;
26pub mod entry;
27pub mod errors;
28pub mod excludes;
29mod gc_lock;
30pub mod index;
31mod io;
32mod jsonio;
33pub mod kind;
34pub mod live_tree;
35mod merge;
36pub mod misc;
37pub mod monitor;
38pub mod owner;
39pub mod restore;
40pub mod show;
41pub mod stats;
42mod stitch;
43mod stored_tree;
44pub mod termui;
45pub mod test_fixtures;
46pub mod transport;
47mod tree;
48pub mod unix_mode;
49pub mod unix_time;
50pub mod validate;
51
52pub use crate::apath::Apath;
53pub use crate::archive::Archive;
54pub use crate::archive::DeleteOptions;
55pub use crate::backup::{backup, BackupOptions, BackupStats};
56pub use crate::band::{Band, BandSelectionPolicy};
57pub use crate::bandid::BandId;
58pub use crate::blockdir::BlockDir;
59pub use crate::blockhash::BlockHash;
60pub use crate::change::{ChangeCallback, EntryChange};
61pub use crate::diff::{diff, DiffOptions};
62pub use crate::entry::{EntryTrait, EntryValue};
63pub use crate::errors::Error;
64pub use crate::excludes::Exclude;
65pub use crate::gc_lock::GarbageCollectionLock;
66pub use crate::index::{IndexEntry, IndexRead, IndexWriter};
67pub use crate::kind::Kind;
68pub use crate::live_tree::LiveTree;
69pub use crate::merge::MergeTrees;
70pub use crate::misc::bytes_to_human_mb;
71pub use crate::owner::Owner;
72pub use crate::restore::{restore, RestoreOptions};
73pub use crate::show::{show_versions, ShowVersionsOptions};
74pub use crate::stats::DeleteStats;
75pub use crate::stored_tree::StoredTree;
76pub use crate::transport::{open_transport, Transport};
77pub use crate::tree::{ReadTree, TreeSize};
78pub use crate::unix_mode::UnixMode;
79pub use crate::validate::ValidateOptions;
80
81pub type Result<T> = std::result::Result<T, Error>;
82
83const VERSION: &str = env!("CARGO_PKG_VERSION");
84
85pub fn version() -> &'static str {
86    VERSION
87}
88
89/// Archive format-compatibility version, normally the first two components of the package version.
90///
91/// (This might be older than the program version.)
92pub const ARCHIVE_VERSION: &str = "0.6";
93
94pub const SYMLINKS_SUPPORTED: bool = cfg!(target_family = "unix");
95
96/// Temporary files in the archive have this prefix.
97const TMP_PREFIX: &str = "tmp";
98
99/// Metadata file in the band directory.
100static BAND_HEAD_FILENAME: &str = "BANDHEAD";
101
102/// Metadata file in the band directory, for closed bands.
103static BAND_TAIL_FILENAME: &str = "BANDTAIL";
104
105/// Length of the binary content hash.
106pub(crate) const BLAKE_HASH_SIZE_BYTES: usize = 64;
107
108/// A callback when an entry is visited.
109pub type EntryCallback<'cb> = Box<dyn Fn(&IndexEntry) + 'cb>;