Skip to content

Commit

Permalink
cd_into_same_dir_as: allow the proper IO error to bubble up and add…
Browse files Browse the repository at this point in the history
… docs
  • Loading branch information
vrmiguel committed Sep 17, 2021
1 parent 8565e47 commit 6085807
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
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)
}
Expand Down

0 comments on commit 6085807

Please sign in to comment.