From 573d60705182507304445ff70cb21f393e923038 Mon Sep 17 00:00:00 2001 From: "Alexis (Poliorcetics) Bourget" Date: Fri, 1 Mar 2024 22:22:25 +0100 Subject: [PATCH] fix: diff hidden but non-ignored files when walking directories --- src/files.rs | 6 ++++-- tests/cli.rs | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/files.rs b/src/files.rs index 7501647bca..940baef8d9 100644 --- a/src/files.rs +++ b/src/files.rs @@ -7,7 +7,7 @@ use std::{ path::{Path, PathBuf}, }; -use ignore::Walk; +use ignore::WalkBuilder; use rustc_hash::FxHashSet; use crate::exit_codes::EXIT_BAD_ARGUMENTS; @@ -228,7 +228,9 @@ pub(crate) fn guess_content(bytes: &[u8]) -> ProbableFileKind { /// All the files in `dir`, including subdirectories. fn relative_file_paths_in_dir(dir: &Path) -> Vec { - Walk::new(dir) + WalkBuilder::new(dir) + .hidden(false) + .build() .filter_map(Result::ok) .map(|entry| Path::new(entry.path()).to_owned()) .filter(|path| !path.is_dir()) diff --git a/tests/cli.rs b/tests/cli.rs index b7c1db4dfd..046d891f80 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -253,9 +253,10 @@ fn walk_hidden_items() { cmd.args(["sample_files/hidden-before", "sample_files/hidden-after"]); - let predicate_fn = predicate::str::contains(".hidden/doc.txt") - .and(predicate::str::contains(".hidden.txt")) - .and(predicate::str::contains("before")) - .and(predicate::str::contains("after")); + let predicate_fn = + predicate::str::contains(format!(".hidden{}doc.txt", std::path::MAIN_SEPARATOR)) + .and(predicate::str::contains(".hidden.txt")) + .and(predicate::str::contains("before")) + .and(predicate::str::contains("after")); cmd.assert().stdout(predicate_fn); }