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