Skip to main content

diskforge_core/rules/
mod.rs

1pub mod android;
2pub mod app_uninstall;
3pub mod dev_artifacts;
4pub mod docker;
5pub mod known_paths;
6pub mod simulator;
7pub mod user_rules;
8
9use crate::types::{Category, CleanableItem, Risk};
10use std::path::PathBuf;
11
12/// A rule that knows how to find cleanable items at known paths
13pub struct KnownPathRule {
14    pub path: PathBuf,
15    pub category: Category,
16    pub description: String,
17    pub risk: Risk,
18    pub regenerates: bool,
19    pub regeneration_hint: Option<String>,
20}
21
22impl KnownPathRule {
23    pub fn into_item(self, size: u64) -> CleanableItem {
24        let last_modified = crate::sizing::dir_last_modified(&self.path);
25        self.into_item_with_stats(size, last_modified)
26    }
27
28    pub fn into_item_with_stats(
29        self,
30        size: u64,
31        last_modified: Option<std::time::SystemTime>,
32    ) -> CleanableItem {
33        CleanableItem {
34            category: self.category,
35            path: self.path,
36            size,
37            risk: self.risk,
38            regenerates: self.regenerates,
39            regeneration_hint: self.regeneration_hint,
40            last_modified,
41            description: self.description,
42            cleanup_command: None,
43        }
44    }
45}