Skip to content
Myr

[ownership] depend on users 0.10.0 on unix; parse user and group names

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alexandru Macovei · committed by David Peter · parent 4f9a024 · Browse files · 4 files+57 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+57 added−2 removed

  • other:+57 added−2 removed

4 files+57 added−2 removed

modified:src/filter/owner.rs+30 added-2 removed
1use anyhow::{anyhow, Result};2use std::fs;34#[derive(Clone, Copy, Debug, PartialEq)]5pub struct OwnerFilter {6 uid: Option<u32>,
6 unmodified lines
13 let (fst, snd) = (it.next(), it.next());1415 let uid = match fst {16 Some("") | None => None,16 Some(s) => Some(s.parse()?),17 Some(s) => {18 let maybe_uid = s19 .parse()20 .ok()21 .or_else(|| users::get_user_by_name(s).map(|user| user.uid()));22 match maybe_uid {23 Some(uid) => Some(uid),24 _ => return Err(anyhow!("'{}' is not a recognized user name", s)),25 }26 }27 };28 let gid = match snd {29 Some("") | None => None,20 Some(s) => Some(s.parse()?),30 Some(s) => {31 let maybe_gid = s32 .parse()33 .ok()34 .or_else(|| users::get_group_by_name(s).map(|group| group.gid()));35 match maybe_gid {36 Some(gid) => Some(gid),37 _ => return Err(anyhow!("'{}' is not a recognized group name", s)),38 }39 }40 };4142 if uid.is_none() && gid.is_none() {43 Err(anyhow!(
3 unmodified lines
47 } else {48 Ok(OwnerFilter { uid, gid })49 }50 }5152 pub fn matches(&self, md: &fs::Metadata) -> bool {53 use std::os::unix::fs::MetadataExt;5455 let uid_ok = self.uid.map(|u| u == md.uid()).unwrap_or(true);56 let gid_ok = self.gid.map(|g| g == md.gid()).unwrap_or(true);5758 uid_ok && gid_ok59 }60}6162#[cfg(test)]63mod owner_parsing {
26 unmodified lines
modified:src/walk.rs+13 added
409 unmodified lines
410 return ignore::WalkState::Continue;411 }412 }413414 #[cfg(unix)]415 {416 if let Some(ref owner_constraint) = config.owner_constraint {417 if let Ok(ref metadata) = entry_path.metadata() {418 if !owner_constraint.matches(&metadata) {419 return ignore::WalkState::Continue;420 }421 } else {422 return ignore::WalkState::Continue;423 }424 }425 }426427 // Filter out unwanted sizes if it is a file and we have been given size constraints.428 if !config.size_constraints.is_empty() {429 if entry_path.is_file() {430 if let Ok(metadata) = entry_path.metadata() {
42 unmodified lines
modified:Cargo.lock+11 added
135 unmodified lines
136 "num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)",137 "regex 1.3.6 (registry+https://github.com/rust-lang/crates.io-index)",138 "regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)",139 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",140 "users 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",141 "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",142]143144[[package]]
266 unmodified lines
411version = "0.1.7"412source = "registry+https://github.com/rust-lang/crates.io-index"413414[[package]]415name = "users"416version = "0.10.0"417source = "registry+https://github.com/rust-lang/crates.io-index"418dependencies = [419 "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)",420 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",421]422423[[package]]424name = "vec_map"425version = "0.8.1"426source = "registry+https://github.com/rust-lang/crates.io-index"427
103 unmodified lines
531"checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327"532"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"533"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"534"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"535"checksum users 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa4227e95324a443c9fcb06e03d4d85e91aabe9a5a02aa818688b6918b6af486"536"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"537"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"538"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"539"checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d"
6 unmodified lines
modified:Cargo.toml+3 added