Skip to content

Commit

Permalink
Properly handle directories
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Dec 2, 2020
1 parent 674c9d8 commit 60bba6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,21 @@ pub fn run(mut args: CliArgs) {

for path in paths {
if path.is_dir() {
let path = continue_error!(path.canonicalize(), "Failed to canonicalize '{:?}'", path);

for (maybe_crate_id, src_dir) in file_finder::crate_and_src() {
code_error!(
1,
env::set_current_dir(&start_dir),
"Failed to set current directory back to '{:?}'",
start_dir
);
if !src_dir
.parent()
.expect("A source dir will always have a parent")
.starts_with(&path)
{
// file_finder::crate_and_src will find every crate in the
// current workspace regardless of the current directory.
// To prevent this we skip the files that are outside of
// the currently considered directory.
continue;
}

match Krate::new(&maybe_crate_id) {
Some(_) => args.krate = maybe_crate_id,
None => {
Expand All @@ -121,6 +129,7 @@ pub fn run(mut args: CliArgs) {
args.krate = default_crate.clone();
}
}

code_error!(
1,
env::set_current_dir(&src_dir),
Expand All @@ -135,6 +144,13 @@ pub fn run(mut args: CliArgs) {
&file_config,
);
}

code_error!(
1,
env::set_current_dir(&start_dir),
"Failed to set current directory back to '{:?}'",
start_dir
);
}
} else {
if args.krate != default_crate {
Expand Down

0 comments on commit 60bba6a

Please sign in to comment.