1extern crate fs_err as fs;
2
3use anyhow::{anyhow, Context};
4use std::path::Path;
5
6pub mod backup;
7mod chunks_reader;
8pub mod medium;
9pub mod model;
10mod pipe;
11pub mod restore;
12mod streaming_crypto;
13
14type Permissions = Option<u32>;
16
17#[allow(non_upper_case_globals)]
18const KiB: usize = 1024;
19#[allow(non_upper_case_globals)]
20const MiB: usize = 1024 * KiB;
21
22const IO_BUFFER_SIZE: usize = 2 * MiB;
24
25const CHUNK_SIZE: usize = 1 * MiB;
29
30const MAX_RESTORE_CHUNK_SIZE: usize = 256 * MiB;
33
34const APPROX_MAX_BLOCK_SIZE: usize = 64 * MiB;
42
43fn get_file_name(path: &Path) -> anyhow::Result<String> {
44 path.file_name()
45 .context("missing file name")?
46 .to_str()
47 .ok_or_else(|| anyhow!("invalid UTF-8 in path: {}", path.display()))
48 .map(str::to_owned)
49}
50
51#[cfg(unix)]
52fn get_file_permissions(path: &Path) -> anyhow::Result<Permissions> {
53 let metadata = fs::metadata(path)?;
54 use std::os::unix::fs::MetadataExt;
55 Ok(Some(metadata.mode()))
56}
57
58#[cfg(not(unix))]
59fn get_file_permissions(_path: &Path) -> anyhow::Result<Permissions> {
60 Ok(None)
61}