ctb_io_csc/csc.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Checksummed Copy (`csc`): Attempts to provide high-integrity, crash-safe, verified, resumable file tree copying. Not yet ready for production use. Has some caveats around its use - see docs/csc-safety.md. In particular, other applications modifying the source or target directory trees can completely mess it up.
21
22#[allow(
23 unused_imports,
24 clippy::wildcard_imports,
25 reason = "Standard workspace crate prelude"
26)]
27pub(crate) use ctb_utilities::*;
28
29pub mod archive;
30pub mod args;
31pub mod cli;
32pub mod copy_engine;
33pub mod diff_engine;
34pub mod index_engine;
35pub mod index_meta;
36pub mod journal;
37pub mod move_engine;
38pub mod path_resolution;
39pub mod search_engine;
40mod section;
41pub mod verifier;
42
43#[cfg(all(test, unix))]
44pub(crate) fn run_permission_test_unprivileged(
45 test_path: &str,
46) -> Result<bool> {
47 use std::os::unix::process::CommandExt;
48 if nix::unistd::geteuid().as_raw() != 0 {
49 return Ok(false);
50 }
51 let output = std::process::Command::new(std::env::current_exe()?)
52 .arg("--exact")
53 .arg(test_path)
54 .arg("--nocapture")
55 .env_remove("CTB_TEST_STORAGE_DIR")
56 .uid(65534)
57 .gid(65534)
58 .output()?;
59 let stdout = String::from_utf8_lossy(&output.stdout);
60 let stderr = String::from_utf8_lossy(&output.stderr);
61 anyhow::ensure!(
62 output.status.success() && stdout.contains("1 passed"),
63 "Unprivileged permission test failed: {stdout}\n{stderr}"
64 );
65 Ok(true)
66}