Skip to content

Commit

Permalink
kondo-lib: don't panic in path_canonicalise (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel committed Dec 9, 2021
1 parent 481cba9 commit 963e12f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions kondo-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{error, fs, path};
use std::{
error::{self, Error},
fs, path,
};

const SYMLINK_FOLLOW: bool = true;

Expand Down Expand Up @@ -329,13 +332,13 @@ pub fn clean(project_path: &str) -> Result<(), Box<dyn error::Error>> {

Ok(())
}

pub fn path_canonicalise(base: &path::Path, tail: path::PathBuf) -> path::PathBuf {
pub fn path_canonicalise(
base: &path::Path,
tail: path::PathBuf,
) -> Result<path::PathBuf, Box<dyn Error>> {
if tail.is_absolute() {
tail
Ok(tail)
} else {
base.join(tail)
.canonicalize()
.expect("Unable to canonicalize!")
Ok(base.join(tail).canonicalize()?)
}
}
14 changes: 7 additions & 7 deletions kondo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ struct Opt {

fn prepare_directories(dirs: Vec<PathBuf>) -> Result<Vec<PathBuf>, Box<dyn Error>> {
let cd = current_dir()?;
Ok(if dirs.is_empty() {
vec![cd]
} else {
dirs.into_iter()
.map(|d| path_canonicalise(&cd, d))
.collect()
})
if dirs.is_empty() {
return Ok(vec![cd]);
}

dirs.into_iter()
.map(|d| path_canonicalise(&cd, d))
.collect()
}

fn main() -> Result<(), Box<dyn Error>> {
Expand Down

0 comments on commit 963e12f

Please sign in to comment.