aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-09 02:33:12 -0400
committerdiogo464 <[email protected]>2021-07-09 02:33:12 -0400
commitc0ef13ca78390fe5176eeb8fca3b35e4bf1f64a2 (patch)
tree85d6a0a5a1a38b75b25c4e43872f15df1b02db2d
parented0baec0a3f953c99445f6842dadc5566e89cb75 (diff)
Removed some unused code in the link command
-rw-r--r--dotup_cli/src/commands/link.rs85
1 files changed, 0 insertions, 85 deletions
diff --git a/dotup_cli/src/commands/link.rs b/dotup_cli/src/commands/link.rs
index fd99253..87453bd 100644
--- a/dotup_cli/src/commands/link.rs
+++ b/dotup_cli/src/commands/link.rs
@@ -14,26 +14,6 @@ pub struct Opts {
14 paths: Vec<PathBuf>, 14 paths: Vec<PathBuf>,
15} 15}
16 16
17/*
18 config/
19 nvim/
20 init.vim
21 lua/
22 setup.lua
23 bash/
24 .bashrc
25
26 link nvim .config/nvim
27 nvim/init.vim -> .config/nvim/init.vim
28 nvim/lua/setup.lua -> config/nvim/lua/setup.lua
29
30 link bash .
31 bash/.bashrc -> ./.bashrc
32
33 link --directory scripts .scripts
34 scripts/ -> ./.scripts
35*/
36
37pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { 17pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
38 let mut depot = utils::read_depot(&config.archive_path)?; 18 let mut depot = utils::read_depot(&config.archive_path)?;
39 19
@@ -64,21 +44,6 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
64 } 44 }
65 } 45 }
66 46
67 //if let Some(destination) = destination {
68 // for origin in origins {
69 // let origin_canonical = origin.canonicalize()?;
70 // let base = if origin_canonical.is_file() {
71 // origin_canonical.parent().unwrap().to_path_buf()
72 // } else {
73 // origin_canonical.to_path_buf()
74 // };
75
76 // link(&mut depot, origin.as_path(), destination.as_path(), &base)?;
77 // }
78 //} else {
79 // log::warn!("Missing destination");
80 //}
81
82 utils::write_depot(&depot)?; 47 utils::write_depot(&depot)?;
83 48
84 Ok(()) 49 Ok(())
@@ -129,53 +94,3 @@ fn collect_file_type(
129 94
130 Ok(collected) 95 Ok(collected)
131} 96}
132
133fn link(depot: &mut Depot, origin: &Path, destination: &Path, base: &Path) -> anyhow::Result<()> {
134 let metadata = std::fs::metadata(origin)?;
135 if metadata.is_file() {
136 link_file(depot, origin, destination, base)?;
137 } else if metadata.is_dir() {
138 link_directory_recursive(depot, origin, destination, base)?;
139 } else {
140 unimplemented!()
141 }
142 Ok(())
143}
144
145fn link_file(
146 depot: &mut Depot,
147 origin: &Path,
148 destination: &Path,
149 base: &Path,
150) -> anyhow::Result<()> {
151 let origin_canonical = origin
152 .canonicalize()
153 .expect("Failed to canonicalize origin path");
154 let partial = origin_canonical
155 .strip_prefix(base)
156 .expect("Failed to remove prefix from origin path");
157 let destination = destination.join(partial);
158
159 let link_desc = LinkDesc {
160 origin: origin_canonical,
161 destination,
162 };
163
164 log::debug!("Linking file {:#?}", link_desc);
165 depot.create_link(link_desc)?;
166
167 Ok(())
168}
169
170fn link_directory_recursive(
171 depot: &mut Depot,
172 dir_path: &Path,
173 destination: &Path,
174 base: &Path,
175) -> anyhow::Result<()> {
176 for origin in dir_path.read_dir()? {
177 let origin = origin?.path();
178 link(depot, &origin, destination, base)?;
179 }
180 Ok(())
181}