Skip to main content
← dvs documentation Rust API reference

dvs/
lib.rs

1pub mod audit;
2pub mod backends;
3mod cache;
4pub mod config;
5mod files;
6mod gitignore;
7pub mod globbing;
8mod hashes;
9pub mod init;
10pub mod paths;
11pub mod progress;
12pub(crate) mod utils;
13
14pub use backends::Backend;
15pub use config::Compression;
16pub use files::add::{AddDetail, AddResult, add_files};
17pub use files::get::{GetDetail, GetResult, get_files};
18pub use files::metadata::FileMetadata;
19pub use files::status::{FileStatus, StatusDetail, StatusFilter, get_status};
20pub use files::types::{Outcome, Status};
21pub use hashes::{HashAlg, Hashes};
22pub use paths::{AddPathStatus, DvsPaths, find_repo_root};
23pub use progress::FileProgress;
24pub use utils::{format_size, set_num_threads};
25
26pub const VERSION: &str = env!("CARGO_PKG_VERSION");
27
28#[cfg(test)]
29pub mod testutil {
30    use crate::config::Config;
31    use crate::init::init;
32    use fs_err as fs;
33    use std::path::{Path, PathBuf};
34    use tempfile::TempDir;
35
36    /// Creates a temporary directory with a .git folder (simulating a git repo).
37    /// Returns the TempDir (owns the directory) and the path to the repo root.
38    ///
39    /// IMPORTANT: Keep the TempDir alive for the duration of the test,
40    /// otherwise the directory gets deleted.
41    pub fn create_temp_git_repo() -> (TempDir, PathBuf) {
42        let tmp = tempfile::tempdir().unwrap();
43        let repo_root = fs::canonicalize(tmp.path()).unwrap();
44        fs::create_dir(repo_root.join(".git")).unwrap();
45        (tmp, repo_root)
46    }
47
48    /// Creates a file with the given content at the specified path.
49    /// Creates parent directories if needed.
50    /// Returns the full path to the created file.
51    pub fn create_file(dir: &Path, relative_path: &str, content: &[u8]) -> PathBuf {
52        let path = dir.join(relative_path);
53        if let Some(parent) = path.parent() {
54            fs::create_dir_all(parent).ok();
55        }
56        fs::write(&path, content).unwrap();
57        path
58    }
59
60    /// Initializes a DVS repository in the given directory.
61    /// Creates storage at `{repo_root}/.storage` and metadata at `{repo_root}/.dvs`.
62    /// Returns (config, dvs_metadata_dir).
63    pub fn init_dvs_repo(repo_root: &Path) -> (Config, PathBuf) {
64        let storage_dir = repo_root.join(".storage");
65        let config = Config::new_local(&storage_dir, None).unwrap();
66        init(repo_root, config.clone()).unwrap();
67        let dvs_dir = repo_root.join(".dvs");
68        (config, dvs_dir)
69    }
70}