From b725422dd7db3c0da595575b444b3725b9b33a9d Mon Sep 17 00:00:00 2001 From: diogo464 Date: Thu, 23 Dec 2021 21:55:39 +0000 Subject: weakly_canonical abort instead of returning error --- dotup/src/depot.rs | 8 ++++---- dotup/src/utils.rs | 10 +++++----- dotup/tests/integration_tests.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dotup/src/depot.rs b/dotup/src/depot.rs index d1e0946..d6f84e8 100644 --- a/dotup/src/depot.rs +++ b/dotup/src/depot.rs @@ -132,7 +132,7 @@ impl Link { } /// Where this link would be installed with the given `install_base`. - pub fn install_destination(&self, install_base: &Path) -> std::io::Result { + pub fn install_destination(&self, install_base: &Path) -> PathBuf { utils::weakly_canonical(install_base.join(self.destination())) } } @@ -258,7 +258,7 @@ fn depot_archive(depot: &Depot) -> Archive { fn depot_create_link(depot: &Depot, link_desc: LinkCreateParams) -> Result { // link_ensure_relative_path(&link_desc.origin)?; link_ensure_relative_path(&link_desc.destination)?; - debug_assert!(utils::is_canonical(depot.base_path())?); + debug_assert!(utils::is_canonical(depot.base_path())); // Check if the file/directory at origin actually exists let origin_joined = depot.base_path().join(&link_desc.origin); @@ -327,7 +327,7 @@ fn depot_install_link( install_base: &Path, ) -> Result<(), LinkInstallError> { let final_origin = link.origin_canonical(); - let final_destination = link.install_destination(install_base)?; + let final_destination = link.install_destination(install_base); log::debug!("Final origin : {}", final_origin.display()); log::debug!("Final destination : {}", final_destination.display()); @@ -374,7 +374,7 @@ fn depot_install_link( fn depot_uninstall_link(_depot: &Depot, link: &Link, install_base: &Path) -> Result<()> { let origin_canonical = link.origin_canonical(); - let install_destination = link.install_destination(install_base)?; + let install_destination = link.install_destination(install_base); let link_target = match std::fs::read_link(&install_destination) { Ok(target) => target, Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(()), diff --git a/dotup/src/utils.rs b/dotup/src/utils.rs index 3a49e8f..c9ea959 100644 --- a/dotup/src/utils.rs +++ b/dotup/src/utils.rs @@ -22,13 +22,13 @@ pub fn is_directory(path: impl AsRef) -> std::io::Result { Ok(metadata.is_dir()) } -pub fn is_canonical(path: &Path) -> std::io::Result { - Ok(path == path.canonicalize()?.as_path()) +pub fn is_canonical(path: &Path) -> bool { + path == weakly_canonical(path).as_path() } -pub fn weakly_canonical(path: impl AsRef) -> std::io::Result { - let cwd = std::env::current_dir()?; - Ok(weakly_canonical_cwd(path, cwd)) +pub fn weakly_canonical(path: impl AsRef) -> PathBuf { + let cwd = std::env::current_dir().expect("Failed to obtain current directory"); + weakly_canonical_cwd(path, cwd) } fn weakly_canonical_cwd(path: impl AsRef, cwd: PathBuf) -> PathBuf { diff --git a/dotup/tests/integration_tests.rs b/dotup/tests/integration_tests.rs index ea64136..d6bed8d 100644 --- a/dotup/tests/integration_tests.rs +++ b/dotup/tests/integration_tests.rs @@ -114,13 +114,13 @@ fn test_depot_install_uninstall_link() { } for link in depot.links() { - let link_path = link.install_destination(install_base).unwrap(); + let link_path = link.install_destination(install_base); let link_target = std::fs::read_link(&link_path).unwrap(); assert_eq!(link_target.canonicalize().unwrap(), link.origin_canonical()); } for link in depot.links() { depot.uninstall_link(link, install_base).unwrap(); - assert!(!link.install_destination(install_base).unwrap().exists()); + assert!(!link.install_destination(install_base).exists()); } } -- cgit