From c0ef13ca78390fe5176eeb8fca3b35e4bf1f64a2 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Fri, 9 Jul 2021 02:33:12 -0400 Subject: Removed some unused code in the link command --- dotup_cli/src/commands/link.rs | 85 ------------------------------------------ 1 file changed, 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 { paths: Vec, } -/* - config/ - nvim/ - init.vim - lua/ - setup.lua - bash/ - .bashrc - - link nvim .config/nvim - nvim/init.vim -> .config/nvim/init.vim - nvim/lua/setup.lua -> config/nvim/lua/setup.lua - - link bash . - bash/.bashrc -> ./.bashrc - - link --directory scripts .scripts - scripts/ -> ./.scripts -*/ - pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { let mut depot = utils::read_depot(&config.archive_path)?; @@ -64,21 +44,6 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { } } - //if let Some(destination) = destination { - // for origin in origins { - // let origin_canonical = origin.canonicalize()?; - // let base = if origin_canonical.is_file() { - // origin_canonical.parent().unwrap().to_path_buf() - // } else { - // origin_canonical.to_path_buf() - // }; - - // link(&mut depot, origin.as_path(), destination.as_path(), &base)?; - // } - //} else { - // log::warn!("Missing destination"); - //} - utils::write_depot(&depot)?; Ok(()) @@ -129,53 +94,3 @@ fn collect_file_type( Ok(collected) } - -fn link(depot: &mut Depot, origin: &Path, destination: &Path, base: &Path) -> anyhow::Result<()> { - let metadata = std::fs::metadata(origin)?; - if metadata.is_file() { - link_file(depot, origin, destination, base)?; - } else if metadata.is_dir() { - link_directory_recursive(depot, origin, destination, base)?; - } else { - unimplemented!() - } - Ok(()) -} - -fn link_file( - depot: &mut Depot, - origin: &Path, - destination: &Path, - base: &Path, -) -> anyhow::Result<()> { - let origin_canonical = origin - .canonicalize() - .expect("Failed to canonicalize origin path"); - let partial = origin_canonical - .strip_prefix(base) - .expect("Failed to remove prefix from origin path"); - let destination = destination.join(partial); - - let link_desc = LinkDesc { - origin: origin_canonical, - destination, - }; - - log::debug!("Linking file {:#?}", link_desc); - depot.create_link(link_desc)?; - - Ok(()) -} - -fn link_directory_recursive( - depot: &mut Depot, - dir_path: &Path, - destination: &Path, - base: &Path, -) -> anyhow::Result<()> { - for origin in dir_path.read_dir()? { - let origin = origin?.path(); - link(depot, &origin, destination, base)?; - } - Ok(()) -} -- cgit