Skip to main content

sandlock_core/
dry_run.rs

1use crate::result::RunResult;
2use std::fmt;
3use std::path::PathBuf;
4
5/// Kind of filesystem change detected by dry-run.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ChangeKind {
8    /// File was created (exists in upper but not in workdir).
9    Added,
10    /// File was modified (exists in both, content differs).
11    Modified,
12    /// File was deleted.
13    Deleted,
14}
15
16impl fmt::Display for ChangeKind {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            ChangeKind::Added => write!(f, "A"),
20            ChangeKind::Modified => write!(f, "M"),
21            ChangeKind::Deleted => write!(f, "D"),
22        }
23    }
24}
25
26/// A single filesystem change detected by dry-run.
27#[derive(Debug, Clone)]
28pub struct Change {
29    pub kind: ChangeKind,
30    /// Path relative to workdir.
31    pub path: PathBuf,
32}
33
34impl fmt::Display for Change {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        write!(f, "{}  {}", self.kind, self.path.display())
37    }
38}
39
40/// Result of a dry-run execution.
41#[derive(Debug)]
42pub struct DryRunResult {
43    pub run_result: RunResult,
44    pub changes: Vec<Change>,
45}