-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support for filtering orphaned files with --owner orphan #1841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d33fbbc
cd9fc62
cd6b72d
763e885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ enum Check<T> { | |
| Equal(T), | ||
| NotEq(T), | ||
| Ignore, | ||
| Orphaned, | ||
| } | ||
|
|
||
| impl OwnerFilter { | ||
|
|
@@ -69,7 +70,17 @@ impl OwnerFilter { | |
| pub fn matches(&self, md: &fs::Metadata) -> bool { | ||
| use std::os::unix::fs::MetadataExt; | ||
|
|
||
| self.uid.check(md.uid()) && self.gid.check(md.gid()) | ||
| let uid_match = match self.uid { | ||
| Check::Orphaned => User::from_uid(md.uid().into()).ok().flatten().is_none(), | ||
|
||
| _ => self.uid.check(md.uid()), | ||
| }; | ||
|
|
||
| let gid_match = match self.gid { | ||
| Check::Orphaned => Group::from_gid(md.gid().into()).ok().flatten().is_none(), | ||
| _ => self.gid.check(md.gid()), | ||
| }; | ||
|
|
||
| uid_match && gid_match | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -79,6 +90,7 @@ impl<T: PartialEq> Check<T> { | |
| Check::Equal(x) => v == *x, | ||
| Check::NotEq(x) => v != *x, | ||
| Check::Ignore => true, | ||
| Check::Orphaned => unreachable!("Orphaned check handled in OwnerFilter::matches"), | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -88,6 +100,7 @@ impl<T: PartialEq> Check<T> { | |
| { | ||
| let (s, equality) = match s { | ||
| Some("") | None => return Ok(Check::Ignore), | ||
| Some("orphan") => return Ok(Check::Orphaned), | ||
| Some(s) if s.starts_with('!') => (&s[1..], false), | ||
| Some(s) => (s, true), | ||
| }; | ||
|
|
@@ -134,6 +147,10 @@ mod owner_parsing { | |
| both_negate:"!4:!3" => Ok(OwnerFilter { uid: NotEq(4), gid: NotEq(3) }), | ||
| uid_not_gid:"6:!8" => Ok(OwnerFilter { uid: Equal(6), gid: NotEq(8) }), | ||
|
|
||
| orphan_uid: "orphan" => Ok(OwnerFilter { uid: Orphaned, gid: Ignore }), | ||
|
||
| orphan_gid: ":orphan" => Ok(OwnerFilter { uid: Ignore, gid: Orphaned }), | ||
| orphan_both:"orphan:orphan"=> Ok(OwnerFilter { uid: Orphaned, gid: Orphaned }), | ||
|
|
||
| more_colons:"3:5:" => Err(_), | ||
| only_colons:"::" => Err(_), | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move forward with this, you'll also need to update the man page and CHANGELOG