From d027ec1c61b28c1ab914d61dd3dbce15af5a820e Mon Sep 17 00:00:00 2001 From: diogo464 Date: Sat, 30 Oct 2021 19:47:49 +0100 Subject: Small changes --- dotup/src/depot.rs | 6 +++++- dotup_cli/src/commands/link.rs | 16 +++++++++------- dotup_cli/src/utils.rs | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/dotup/src/depot.rs b/dotup/src/depot.rs index 4997996..5ee8f1a 100644 --- a/dotup/src/depot.rs +++ b/dotup/src/depot.rs @@ -159,6 +159,7 @@ struct DepotShared { #[derive(Debug)] pub struct Depot { + // TODO: remove shared shared: Arc, // Maps the origin to the link links: SlotMap, @@ -166,12 +167,15 @@ pub struct Depot { } impl Depot { + /// Creates a new [`Depot`] using the config. + /// Fails if any of the links in the provided archive fail to be created. pub fn new(config: DepotConfig) -> Result { depot_create(config) } /// Creates a new link from the description. /// The origin path must exist. + /// If a link with the same origin already existed then it is replaced. pub fn create_link(&mut self, link_desc: LinkCreateParams) -> Result { let link = depot_create_link(self, link_desc)?; let link_id = depot_insert_link(self, link); @@ -267,6 +271,7 @@ fn depot_create_link(depot: &Depot, link_desc: LinkCreateParams) -> Result Result, } +// TODO: require destination +// remove else branch pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { let mut depot = utils::read_depot(&config.archive_path)?; @@ -43,7 +45,7 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { } else { let mut params = Vec::new(); for origin in origins { - link(&depot, origin, destination, origin, &mut params)?; + generate_link_params(&depot, origin, destination, origin, &mut params)?; } params }; @@ -69,7 +71,7 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { Ok(()) } -fn link( +fn generate_link_params( depot: &Depot, origin: &Path, destination: &Path, @@ -78,14 +80,14 @@ fn link( ) -> anyhow::Result<()> { let metadata = std::fs::metadata(origin)?; if metadata.is_file() { - link_file(depot, origin, destination, base, params)?; + generate_file_link_params(depot, origin, destination, base, params)?; } else if metadata.is_dir() { - link_directory_recursive(depot, origin, destination, base, params)?; + generate_directory_link_params_recursive(depot, origin, destination, base, params)?; } Ok(()) } -fn link_file( +fn generate_file_link_params( depot: &Depot, origin: &Path, destination: &Path, @@ -118,7 +120,7 @@ fn link_file( Ok(()) } -fn link_directory_recursive( +fn generate_directory_link_params_recursive( depot: &Depot, dir_path: &Path, destination: &Path, @@ -127,7 +129,7 @@ fn link_directory_recursive( ) -> anyhow::Result<()> { for origin in dir_path.read_dir()? { let origin = origin?.path(); - link(depot, &origin, destination, base, params)?; + generate_link_params(depot, &origin, destination, base, params)?; } Ok(()) } diff --git a/dotup_cli/src/utils.rs b/dotup_cli/src/utils.rs index d284a22..a5c7647 100644 --- a/dotup_cli/src/utils.rs +++ b/dotup_cli/src/utils.rs @@ -83,8 +83,8 @@ pub fn read_depot(archive_path: impl AsRef) -> anyhow::Result { let archive_path = archive_path.as_ref().to_path_buf(); let archive = read_archive(&archive_path)?; let depot_config = DepotConfig { - archive_path, archive: Default::default(), + archive_path, }; let mut depot = Depot::new(depot_config)?; -- cgit