dodot_lib/handlers/
path.rs1use std::path::Path;
4
5use crate::datastore::DataStore;
6use crate::handlers::{Handler, HandlerCategory, HandlerConfig, HandlerStatus, HANDLER_PATH};
7use crate::operations::HandlerIntent;
8use crate::paths::Pather;
9use crate::rules::RuleMatch;
10use crate::Result;
11
12pub struct PathHandler;
13
14impl Handler for PathHandler {
15 fn name(&self) -> &str {
16 HANDLER_PATH
17 }
18
19 fn category(&self) -> HandlerCategory {
20 HandlerCategory::Configuration
21 }
22
23 fn to_intents(
24 &self,
25 matches: &[RuleMatch],
26 _config: &HandlerConfig,
27 _paths: &dyn Pather,
28 ) -> Result<Vec<HandlerIntent>> {
29 Ok(matches
30 .iter()
31 .filter(|m| m.is_dir)
32 .map(|m| HandlerIntent::Stage {
33 pack: m.pack.clone(),
34 handler: HANDLER_PATH.into(),
35 source: m.absolute_path.clone(),
36 })
37 .collect())
38 }
39
40 fn check_status(
41 &self,
42 file: &Path,
43 pack: &str,
44 datastore: &dyn DataStore,
45 ) -> Result<HandlerStatus> {
46 let has_state = datastore.has_handler_state(pack, HANDLER_PATH)?;
47 Ok(HandlerStatus {
48 file: file.to_string_lossy().into_owned(),
49 handler: HANDLER_PATH.into(),
50 deployed: has_state,
51 message: if has_state {
52 "added to PATH".into()
53 } else {
54 "not in PATH".into()
55 },
56 })
57 }
58}