diff options
| author | diogo464 <[email protected]> | 2021-12-23 21:55:39 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2021-12-23 21:57:52 +0000 |
| commit | b725422dd7db3c0da595575b444b3725b9b33a9d (patch) | |
| tree | 04a15f8f12733c5ec1ff0697f35017cc9e95fa84 | |
| parent | 2ec4ae9c01c56e8e1b9bf619578278e9f8a06449 (diff) | |
weakly_canonical abort instead of returning error
| -rw-r--r-- | dotup/src/depot.rs | 8 | ||||
| -rw-r--r-- | dotup/src/utils.rs | 10 | ||||
| -rw-r--r-- | 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 { | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | /// Where this link would be installed with the given `install_base`. | 134 | /// Where this link would be installed with the given `install_base`. |
| 135 | pub fn install_destination(&self, install_base: &Path) -> std::io::Result<PathBuf> { | 135 | pub fn install_destination(&self, install_base: &Path) -> PathBuf { |
| 136 | utils::weakly_canonical(install_base.join(self.destination())) | 136 | utils::weakly_canonical(install_base.join(self.destination())) |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| @@ -258,7 +258,7 @@ fn depot_archive(depot: &Depot) -> Archive { | |||
| 258 | fn depot_create_link(depot: &Depot, link_desc: LinkCreateParams) -> Result<Link, LinkCreateError> { | 258 | fn depot_create_link(depot: &Depot, link_desc: LinkCreateParams) -> Result<Link, LinkCreateError> { |
| 259 | // link_ensure_relative_path(&link_desc.origin)?; | 259 | // link_ensure_relative_path(&link_desc.origin)?; |
| 260 | link_ensure_relative_path(&link_desc.destination)?; | 260 | link_ensure_relative_path(&link_desc.destination)?; |
| 261 | debug_assert!(utils::is_canonical(depot.base_path())?); | 261 | debug_assert!(utils::is_canonical(depot.base_path())); |
| 262 | 262 | ||
| 263 | // Check if the file/directory at origin actually exists | 263 | // Check if the file/directory at origin actually exists |
| 264 | let origin_joined = depot.base_path().join(&link_desc.origin); | 264 | let origin_joined = depot.base_path().join(&link_desc.origin); |
| @@ -327,7 +327,7 @@ fn depot_install_link( | |||
| 327 | install_base: &Path, | 327 | install_base: &Path, |
| 328 | ) -> Result<(), LinkInstallError> { | 328 | ) -> Result<(), LinkInstallError> { |
| 329 | let final_origin = link.origin_canonical(); | 329 | let final_origin = link.origin_canonical(); |
| 330 | let final_destination = link.install_destination(install_base)?; | 330 | let final_destination = link.install_destination(install_base); |
| 331 | 331 | ||
| 332 | log::debug!("Final origin : {}", final_origin.display()); | 332 | log::debug!("Final origin : {}", final_origin.display()); |
| 333 | log::debug!("Final destination : {}", final_destination.display()); | 333 | log::debug!("Final destination : {}", final_destination.display()); |
| @@ -374,7 +374,7 @@ fn depot_install_link( | |||
| 374 | 374 | ||
| 375 | fn depot_uninstall_link(_depot: &Depot, link: &Link, install_base: &Path) -> Result<()> { | 375 | fn depot_uninstall_link(_depot: &Depot, link: &Link, install_base: &Path) -> Result<()> { |
| 376 | let origin_canonical = link.origin_canonical(); | 376 | let origin_canonical = link.origin_canonical(); |
| 377 | let install_destination = link.install_destination(install_base)?; | 377 | let install_destination = link.install_destination(install_base); |
| 378 | let link_target = match std::fs::read_link(&install_destination) { | 378 | let link_target = match std::fs::read_link(&install_destination) { |
| 379 | Ok(target) => target, | 379 | Ok(target) => target, |
| 380 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(()), | 380 | 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<Path>) -> std::io::Result<bool> { | |||
| 22 | Ok(metadata.is_dir()) | 22 | Ok(metadata.is_dir()) |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | pub fn is_canonical(path: &Path) -> std::io::Result<bool> { | 25 | pub fn is_canonical(path: &Path) -> bool { |
| 26 | Ok(path == path.canonicalize()?.as_path()) | 26 | path == weakly_canonical(path).as_path() |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | pub fn weakly_canonical(path: impl AsRef<Path>) -> std::io::Result<PathBuf> { | 29 | pub fn weakly_canonical(path: impl AsRef<Path>) -> PathBuf { |
| 30 | let cwd = std::env::current_dir()?; | 30 | let cwd = std::env::current_dir().expect("Failed to obtain current directory"); |
| 31 | Ok(weakly_canonical_cwd(path, cwd)) | 31 | weakly_canonical_cwd(path, cwd) |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | fn weakly_canonical_cwd(path: impl AsRef<Path>, cwd: PathBuf) -> PathBuf { | 34 | fn weakly_canonical_cwd(path: impl AsRef<Path>, 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() { | |||
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | for link in depot.links() { | 116 | for link in depot.links() { |
| 117 | let link_path = link.install_destination(install_base).unwrap(); | 117 | let link_path = link.install_destination(install_base); |
| 118 | let link_target = std::fs::read_link(&link_path).unwrap(); | 118 | let link_target = std::fs::read_link(&link_path).unwrap(); |
| 119 | assert_eq!(link_target.canonicalize().unwrap(), link.origin_canonical()); | 119 | assert_eq!(link_target.canonicalize().unwrap(), link.origin_canonical()); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | for link in depot.links() { | 122 | for link in depot.links() { |
| 123 | depot.uninstall_link(link, install_base).unwrap(); | 123 | depot.uninstall_link(link, install_base).unwrap(); |
| 124 | assert!(!link.install_destination(install_base).unwrap().exists()); | 124 | assert!(!link.install_destination(install_base).exists()); |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
