ccsync_core/sync/
actions.rs

1//! Sync action determination logic
2
3use std::path::PathBuf;
4
5use crate::comparison::{ComparisonResult, ConflictStrategy};
6
7/// Sync action to perform
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum SyncAction {
10    /// Create new file at destination
11    Create {
12        /// Source file path
13        source: PathBuf,
14        /// Destination file path
15        dest: PathBuf,
16    },
17    /// Skip this file (no action needed)
18    Skip {
19        /// File path being skipped
20        path: PathBuf,
21        /// Reason for skipping
22        reason: String,
23    },
24    /// Conflict requiring resolution
25    Conflict {
26        /// Source file path
27        source: PathBuf,
28        /// Destination file path
29        dest: PathBuf,
30        /// Conflict resolution strategy
31        strategy: ConflictStrategy,
32        /// Whether source is newer than destination
33        source_newer: bool,
34    },
35}
36
37/// Resolves comparison results into sync actions
38pub struct SyncActionResolver;
39
40impl SyncActionResolver {
41    /// Determine sync action from comparison result
42    #[must_use]
43    pub fn resolve(source: PathBuf, dest: PathBuf, comparison: &ComparisonResult) -> SyncAction {
44        match comparison {
45            ComparisonResult::Identical => SyncAction::Skip {
46                path: source,
47                reason: "identical content".to_string(),
48            },
49            ComparisonResult::SourceOnly => SyncAction::Create { source, dest },
50            ComparisonResult::DestinationOnly => SyncAction::Skip {
51                path: dest,
52                reason: "source doesn't exist".to_string(),
53            },
54            ComparisonResult::Conflict {
55                source_newer,
56                strategy,
57            } => SyncAction::Conflict {
58                source,
59                dest,
60                strategy: *strategy,
61                source_newer: *source_newer,
62            },
63        }
64    }
65}