Skip to content

Commit

Permalink
Add same file system functionality
Browse files Browse the repository at this point in the history
This adds a `--same-file-system` CLI option that instructs the walker to
not cross file system boundaries.
Due to the fact that the corresponding option of the `ignore` crate's
`WalkBuilder` does not support platforms other than Unix and Windows,
the option does nothing on platforms other than those.
Resolves sharkdp#507
  • Loading branch information
FallenWarrior2k committed Nov 14, 2019
1 parent c14a004 commit c90a7cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,20 @@ USAGE:
fd [FLAGS/OPTIONS] [<pattern>] [<path>...]
FLAGS:
-H, --hidden Search hidden files and directories
-I, --no-ignore Do not respect .(git|fd)ignore files
--no-ignore-vcs Do not respect .gitignore files
-s, --case-sensitive Case-sensitive search (default: smart case)
-i, --ignore-case Case-insensitive search (default: smart case)
-g, --glob Glob-based search (default: regular expression)
-F, --fixed-strings Treat the pattern as a literal string
-a, --absolute-path Show absolute instead of relative paths
-L, --follow Follow symbolic links
-p, --full-path Search full path (default: file-/dirname only)
-0, --print0 Separate results by the null character
-h, --help Prints help information
-V, --version Prints version information
-H, --hidden Search hidden files and directories
-I, --no-ignore Do not respect .(git|fd)ignore files
--no-ignore-vcs Do not respect .gitignore files
-s, --case-sensitive Case-sensitive search (default: smart case)
-i, --ignore-case Case-insensitive search (default: smart case)
-g, --glob Glob-based search (default: regular expression)
-F, --fixed-strings Treat the pattern as a literal string
-a, --absolute-path Show absolute instead of relative paths
-L, --follow Follow symbolic links
--same-file-system Don't cross file system boundaries (only Unix/Windows)
-p, --full-path Search full path (default: file-/dirname only)
-0, --print0 Separate results by the null character
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-d, --max-depth <depth> Set maximum search depth (default: none)
Expand Down
6 changes: 6 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub fn build_app() -> App<'static, 'static> {
.alias("dereference")
.overrides_with("follow"),
)
.arg(arg("same-file-system").long("same-file-system"))
.arg(
arg("full-path")
.long("full-path")
Expand Down Expand Up @@ -321,6 +322,11 @@ fn usage() -> HashMap<&'static str, Help> {
, "Follow symbolic links"
, "By default, fd does not descend into symlinked directories. Using this flag, symbolic \
links are also traversed.");
doc!(h, "same-file-system"
, "Don't cross file system boundaries (only Unix/Windows)"
, "By default, fd will traverse the file system tree as far as other options dictate. \
With this flag, fd ensures that it does not descend into a different file system than \
the one it started in. Does nothing if not on Unix or Windows.");
doc!(h, "full-path"
, "Search full path (default: file-/dirname only)"
, "By default, the search pattern is only matched against the filename (or directory \
Expand Down
3 changes: 3 additions & 0 deletions src/internal/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct FdOptions {
/// Whether to follow symlinks or not.
pub follow_links: bool,

/// Whether to limit the search to starting file system or not.
pub same_file_system: bool,

/// Whether elements of output should be separated by a null character
pub null_separator: bool,

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ fn main() {
|| matches.is_present("rg-alias-hidden-ignore")
|| matches.is_present("no-ignore-vcs")),
follow_links: matches.is_present("follow"),
same_file_system: matches.is_present("same-file-system"),
null_separator: matches.is_present("null_separator"),
max_depth: matches
.value_of("depth")
Expand Down
2 changes: 2 additions & 0 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -
.git_exclude(config.read_vcsignore)
.overrides(overrides)
.follow_links(config.follow_links)
// Same file system is only supported on Unix and Windows platforms
.same_file_system(config.same_file_system && (cfg!(unix) || cfg!(windows)))
.max_depth(config.max_depth);

if config.read_fdignore {
Expand Down

0 comments on commit c90a7cb

Please sign in to comment.