ccsync_core/sync/
actions.rs1use std::path::PathBuf;
4
5use crate::comparison::{ComparisonResult, ConflictStrategy};
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum SyncAction {
10 Create {
12 source: PathBuf,
14 dest: PathBuf,
16 },
17 Skip {
19 path: PathBuf,
21 reason: String,
23 },
24 Conflict {
26 source: PathBuf,
28 dest: PathBuf,
30 strategy: ConflictStrategy,
32 source_newer: bool,
34 },
35}
36
37pub struct SyncActionResolver;
39
40impl SyncActionResolver {
41 #[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}