Skip to content

Commit

Permalink
Merge pull request #107 from solidiquis/issue/106
Browse files Browse the repository at this point in the history
fix issue where not-existent directory as cli arg causes infinite loop
  • Loading branch information
solidiquis authored Mar 30, 2023
2 parents 9a8fc34 + db16a0d commit 37b5165
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/render/context/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ const XDG_CONFIG_HOME: &str = "XDG_CONFIG_HOME";
/// - `$HOME/.config/erdtree/.erdtreerc`
/// - `$HOME/.erdtreerc`
pub fn read_config_to_string<T: AsRef<Path>>(path: Option<T>) -> Option<String> {
path
.map(fs::read_to_string)
.map(Result::ok)
.flatten()
path.map(fs::read_to_string)
.and_then(Result::ok)
.or_else(config_from_config_path)
.or_else(config_from_xdg_path)
.or_else(config_from_home)
Expand Down
3 changes: 1 addition & 2 deletions src/render/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Tree {
/// parallel traversal; post-processing post-processing of all directory entries should
/// be completely CPU-bound.
fn traverse(ctx: &Context) -> Result<(Arena<Node>, NodeId)> {
let walker = WalkParallel::try_from(ctx)?;
let (tx, rx) = mpsc::channel();

thread::scope(|s| {
Expand Down Expand Up @@ -148,8 +149,6 @@ impl Tree {

let mut visitor_builder = BranchVisitorBuilder::new(ctx, Sender::clone(&tx));

let walker = WalkParallel::try_from(ctx)?;

walker.visit(&mut visitor_builder);

tx.send(TraversalState::Done).unwrap();
Expand Down
10 changes: 8 additions & 2 deletions tests/file_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ fn file_count() {
#[test]
fn file_count_report() {
assert_eq!(
utils::run_cmd(&["--count", "--report", "--sort", "name", "--no-config", "tests/data"]),
utils::run_cmd(&[
"--count",
"--report",
"--sort",
"name",
"--no-config",
"tests/data"
]),
indoc!(
"
d 1241 B data
Expand All @@ -45,4 +52,3 @@ fn file_count_report() {
),
)
}

0 comments on commit 37b5165

Please sign in to comment.