From 4f9a02400aee49b632fedb0c5500993cd4e1138e Mon Sep 17 00:00:00 2001 From: Alexandru Macovei Date: Fri, 1 May 2020 15:50:12 +0300 Subject: [PATCH] [ownership] add --owner arg parsing and storage --- src/app.rs | 9 +++++++++ src/main.rs | 11 +++++++++++ src/options.rs | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/src/app.rs b/src/app.rs index 8c23e23..ab7798f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -524,6 +524,15 @@ pub fn build_app() -> App<'static, 'static> { ), ); + if cfg!(unix) { + app = app.arg( + Arg::with_name("owner") + .long("owner") + .short("o") + .takes_value(true), + ); + } + // Make `--one-file-system` available only on Unix and Windows platforms, as per the // restrictions on the corresponding option in the `ignore` crate. // Provide aliases `mount` and `xdev` for people coming from `find`. diff --git a/src/main.rs b/src/main.rs index 377a698..4fb28f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,8 @@ use regex::bytes::{RegexBuilder, RegexSetBuilder}; use crate::exec::CommandTemplate; use crate::exit_codes::ExitCode; use crate::filetypes::FileTypes; +#[cfg(unix)] +use crate::filter::OwnerFilter; use crate::filter::{SizeFilter, TimeFilter}; use crate::options::Options; use crate::regex_helper::pattern_has_uppercase_char; @@ -275,6 +277,13 @@ fn run() -> Result { } } + #[cfg(unix)] + let owner_constraint = if let Some(s) = matches.value_of("owner") { + Some(OwnerFilter::from_string(s)?) + } else { + None + }; + let config = Options { case_sensitive, search_full_path: matches.is_present("full-path"), @@ -358,6 +367,8 @@ fn run() -> Result { .unwrap_or_else(|| vec![]), size_constraints: size_limits, time_constraints, + #[cfg(unix)] + owner_constraint, show_filesystem_errors: matches.is_present("show-errors"), path_separator, max_results: matches diff --git a/src/options.rs b/src/options.rs index 3f52516..19906db 100644 --- a/src/options.rs +++ b/src/options.rs @@ -5,6 +5,8 @@ use regex::bytes::RegexSet; use crate::exec::CommandTemplate; use crate::filetypes::FileTypes; +#[cfg(unix)] +use crate::filter::OwnerFilter; use crate::filter::{SizeFilter, TimeFilter}; /// Configuration options for *fd*. @@ -82,6 +84,10 @@ pub struct Options { /// Constraints on last modification time of files pub time_constraints: Vec, + #[cfg(unix)] + /// User/group ownership constraint + pub owner_constraint: Option, + /// Whether or not to display filesystem errors pub show_filesystem_errors: bool,