ocy_core/
models.rs

1use std::{path::PathBuf, sync::Arc};
2
3#[derive(Debug, PartialEq, Eq, Clone)]
4pub enum SimpleFileKind {
5    File,
6    Directory,
7}
8#[derive(Debug, Clone)]
9pub struct FileInfo {
10    pub path: PathBuf,
11    pub name: String,
12    pub kind: SimpleFileKind,
13}
14
15impl FileInfo {
16    pub(crate) fn new(path: PathBuf, name: String, kind: SimpleFileKind) -> Self {
17        Self { path, name, kind }
18    }
19}
20
21#[derive(Debug)]
22pub enum RemovalAction {
23    Delete {
24        file_info: FileInfo,
25        file_size: Option<u64>,
26    },
27    RunCommand {
28        work_dir: FileInfo,
29        command: Arc<str>,
30    },
31}
32
33#[derive(Debug)]
34pub struct RemovalCandidate {
35    pub matcher_name: Arc<str>,
36    pub action: RemovalAction,
37}
38
39impl RemovalCandidate {
40    pub fn new(matcher_name: Arc<str>, file_info: FileInfo, file_size: Option<u64>) -> Self {
41        let action = RemovalAction::Delete {
42            file_info,
43            file_size,
44        };
45        Self {
46            matcher_name,
47            action,
48        }
49    }
50
51    pub fn new_cmd(matcher_name: Arc<str>, work_dir: FileInfo, command: Arc<str>) -> Self {
52        let action = RemovalAction::RunCommand { work_dir, command };
53        Self {
54            matcher_name,
55            action,
56        }
57    }
58
59    pub fn estimate_file_size(&self) -> u64 {
60        match &self.action {
61            RemovalAction::Delete { file_size, .. } => file_size.unwrap_or(0),
62            RemovalAction::RunCommand { .. } => 0,
63        }
64    }
65
66    pub fn file_size(&self) -> Option<u64> {
67        match &self.action {
68            RemovalAction::Delete { file_size, .. } => *file_size,
69            RemovalAction::RunCommand { .. } => None,
70        }
71    }
72}