From dea1fbe72267eb58ad9f7e40d99dbf9159b1c65f Mon Sep 17 00:00:00 2001 From: Simon Engmann Date: Mon, 30 Dec 2019 22:05:42 +0100 Subject: [PATCH] Restrict `--one-file-system` to supported systems Instead of having the option do nothing at runtime on unsupported platforms, it is now only available on the systems that support it in the first place. --- src/app.rs | 28 ++++++++++++++++++++-------- src/walk.rs | 4 ++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/app.rs b/src/app.rs index 2b3724f..fa0d95b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -37,7 +37,7 @@ pub fn build_app() -> App<'static, 'static> { .long_help(helps[name].long) }; - App::new("fd") + let app = App::new("fd") .version(crate_version!()) .usage("fd [FLAGS/OPTIONS] [] [...]") .setting(AppSettings::ColoredHelp) @@ -115,7 +115,6 @@ pub fn build_app() -> App<'static, 'static> { .alias("dereference") .overrides_with("follow"), ) - .arg(arg("one-file-system").long("one-file-system")) .arg( arg("full-path") .long("full-path") @@ -283,7 +282,16 @@ pub fn build_app() -> App<'static, 'static> { .multiple(true) .hidden_short_help(true) .number_of_values(1), - ) + ); + + // Make `--one-file-system` available only on Unix and Windows platforms, as per the + // restrictions on the corresponding option in the `ignore` crate. + // It's not pretty, but I'm unaware of a way to make just part of a builder chain conditional + if cfg!(unix) || cfg!(windows) { + app.arg(arg("one-file-system").long("one-file-system")) + } else { + app + } } #[rustfmt::skip] @@ -330,11 +338,6 @@ 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, "one-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 \ @@ -463,5 +466,14 @@ fn usage() -> HashMap<&'static str, Help> { results will be shown with respect to the given base path. Note that relative paths \ which are passed to fd via the positional argument or the '--search-path' option \ will also be resolved relative to this directory."); + + if cfg!(unix) || cfg!(windows) { + doc!(h, "one-file-system" + , "Don't cross file system boundaries" + , "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."); + } + h } diff --git a/src/walk.rs b/src/walk.rs index 75f9b5c..335e429 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -78,8 +78,8 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) - .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.one_file_system && (cfg!(unix) || cfg!(windows))) + // No need to check for supported platforms, option is unavailable on unsupported ones + .same_file_system(config.one_file_system) .max_depth(config.max_depth); if config.read_fdignore {