1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00
ripgrep/ignore
Jakub Wieczorek 322fc75a3d ignore: make walker visit untraversable directories
This commit fixes an inconsistency between the serial and the parallel
directory walkers around visiting a directory for which the user holds
insufficient permissions to descend into.

The serial walker does produce a successful entry for a directory that
it cannot descend into due to insufficient permissions. However, before
this change that has not been the case for the parallel walker, which
would produce an `Err` item not only when descending into a directory
that it cannot read from but also for the directory entry itself.

This change brings the behaviour of the parallel variant in line with
that of the serial one.

Fixes #1346, Closes #1365
2020-02-17 17:16:28 -05:00
..
examples deps: update to crossbeam-channel 0.3 2018-12-15 08:40:04 -05:00
src ignore: make walker visit untraversable directories 2020-02-17 17:16:28 -05:00
tests ignore/style: 80 columns, dammit 2018-07-29 08:31:04 -04:00
Cargo.toml ignore: allow parallel walker to borrow data 2020-02-17 17:16:28 -05:00
COPYING Add license files to each crate. 2017-03-12 16:57:15 -04:00
LICENSE-MIT Add license files to each crate. 2017-03-12 16:57:15 -04:00
README.md ripgrep: migrate to libripgrep 2018-08-20 07:10:19 -04:00
UNLICENSE Add license files to each crate. 2017-03-12 16:57:15 -04:00

ignore

The ignore crate provides a fast recursive directory iterator that respects various filters such as globs, file types and .gitignore files. This crate also provides lower level direct access to gitignore and file type matchers.

Linux build status Windows build status

Dual-licensed under MIT or the UNLICENSE.

Documentation

https://docs.rs/ignore

Usage

Add this to your Cargo.toml:

[dependencies]
ignore = "0.4"

and this to your crate root:

extern crate ignore;

Example

This example shows the most basic usage of this crate. This code will recursively traverse the current directory while automatically filtering out files and directories according to ignore globs found in files like .ignore and .gitignore:

use ignore::Walk;

for result in Walk::new("./") {
    // Each item yielded by the iterator is either a directory entry or an
    // error, so either print the path or the error.
    match result {
        Ok(entry) => println!("{}", entry.path().display()),
        Err(err) => println!("ERROR: {}", err),
    }
}

Example: advanced

By default, the recursive directory iterator will ignore hidden files and directories. This can be disabled by building the iterator with WalkBuilder:

use ignore::WalkBuilder;

for result in WalkBuilder::new("./").hidden(false).build() {
    println!("{:?}", result);
}

See the documentation for WalkBuilder for many other options.