From f13a60805df476649e908842f78785ccf47834ed Mon Sep 17 00:00:00 2001 From: diogo464 Date: Fri, 9 Jul 2021 04:15:11 -0400 Subject: Allow linking directories. --- dotup/src/depot.rs | 33 +++++++++++++++++++++++++++++++++ dotup_cli/src/commands/link.rs | 8 +++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dotup/src/depot.rs b/dotup/src/depot.rs index 227d824..0e987d2 100644 --- a/dotup/src/depot.rs +++ b/dotup/src/depot.rs @@ -20,6 +20,10 @@ pub enum LinkCreateError { LinkPathIsNotRelative(PathBuf), #[error("Link origin doesnt exist : {}", .0.display())] LinkOriginDoesntExist(PathBuf), + #[error("Cannot create link for directory {} beacause it has a linked child", .0.display())] + DirectoryHasLinkedChildren(PathBuf), + #[error("Cannot create link for file {} beacause it has a linked parent", .0.display())] + FileHasLinkedParent(PathBuf), #[error(transparent)] IOError(#[from] std::io::Error), } @@ -82,9 +86,16 @@ impl From for LinkCreateParams { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +enum LinkType { + File, + Directory, +} + #[derive(Debug)] pub struct Link { id: LinkID, + ty: LinkType, /// The origin path, when joined with the depot base path, must be valid and it point to a file that exists. origin: PathBuf, /// Canonical version of origin @@ -101,6 +112,10 @@ impl Link { self.id } + fn link_type(&self) -> LinkType { + self.ty + } + /// The relative path to the origin file. Relative from depot folder. pub fn origin(&self) -> &Path { &self.origin @@ -280,8 +295,26 @@ fn depot_create_link(depot: &Depot, link_desc: LinkCreateParams) -> Result anyhow::Result<()> { }; if let Some(destination) = destination { - for path in collect_file_type(origins, FileType::File)? { + let collected_paths = if opts.directory { + origins.to_vec() + } else { + collect_file_type(origins, FileType::File)? + }; + + for path in collected_paths { let link_desc = LinkCreateParams { origin: path, destination: destination.clone(), -- cgit