1use crate::Config;
2use std::process;
3
4pub fn move_link(src_path: &String, dest_path: &String, config: &Config) {
5 let _output_mv = process::Command::new("mv")
6 .arg(src_path)
7 .arg(dest_path)
8 .output()
9 .expect("Failed to execute mv");
10
11 verbose_msg(config, format!(
12 "Executed: `mv {} {}`", src_path, dest_path
13 ));
14}
15
16pub fn redirect_links(links: &Vec<String>, dest_path: &String, config: &Config) {
17 for link in links {
18 let _output_ln = process::Command::new("ln")
19 .arg("-fs")
20 .arg(dest_path)
21 .arg(link)
22 .output()
23 .expect("Failed to execute ln");
24
25 verbose_msg(config, format!(
26 "Executed: `ln -fs {} {}`", dest_path, link
27 ));
28 }
29
30}
31
32pub fn find_links(src_path: &String, links_dir: &String, config: &Config) -> Option<Vec<String>> {
33 let output_find = process::Command::new("find")
34 .arg(links_dir)
35 .arg("-lname")
36 .arg(src_path)
37 .output()
38 .expect("Failed to execute find");
39
40 verbose_msg(config, format!(
41 "Executed: `find {} -lname {}`", links_dir, src_path
42 ));
43
44 let mut links_paths = String::from_utf8_lossy(&output_find.stdout)
45 .split("\n")
46 .map(|s| s.to_string())
47 .collect::<Vec<String>>();
48
49 if links_paths.len() > 1 {
50 links_paths.pop();
51 verbose_msg(config, format!(
52 "Found {} links: {:?} in {}",
53 links_paths.len(),
54 links_paths,
55 links_dir,
56 ));
57 Some(links_paths)
58 } else {
59 verbose_msg(config, format!(
60 "Found 0 links in {}",
61 links_dir,
62 ));
63 None
64 }
65}
66
67fn verbose_msg(config: &Config, msg: String) {
68 if config.verbose {
69 println!("{}", msg);
70 }
71}