From 6085807ddfab25529a4d452b874cd91b3dbc4553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Rodrigues=20Miguel?= Date: Fri, 17 Sep 2021 11:54:55 -0300 Subject: [PATCH] `cd_into_same_dir_as`: allow the proper IO error to bubble up and add docs --- src/utils.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 9a15fd5..5116ccb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -15,14 +15,15 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { Ok(()) } +/// Changes the process' current directory to the directory that contains the +/// file pointed to by `filename` and returns the directory that the process +/// was in before this function was called. pub fn cd_into_same_dir_as(filename: &Path) -> crate::Result { let previous_location = env::current_dir()?; let parent = filename.parent().ok_or(crate::Error::CompressingRootFolder)?; - // TODO: fix this error variant, as it is not the only possible error that can - // come out of this operation - env::set_current_dir(parent).ok().ok_or(crate::Error::CompressingRootFolder)?; + env::set_current_dir(parent)?; Ok(previous_location) }