mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
find: Add -uid
option to filter by owning user ID
This commit is contained in:
parent
d3da8f978e
commit
1bc081398e
2 changed files with 27 additions and 1 deletions
|
@ -78,6 +78,8 @@ by the current user.
|
||||||
symbolic link is used.
|
symbolic link is used.
|
||||||
* `-gid [-|+]number`: Checks if the file is owned by a group with an ID less
|
* `-gid [-|+]number`: Checks if the file is owned by a group with an ID less
|
||||||
than, greater than or exactly `number`.
|
than, greater than or exactly `number`.
|
||||||
|
* `-uid [-|+]number`: Checks if the file is owned by a user with an ID less
|
||||||
|
than, greater than or exactly `number`.
|
||||||
* `-print`: Outputs the file path, followed by a newline. Always evaluates to
|
* `-print`: Outputs the file path, followed by a newline. Always evaluates to
|
||||||
true.
|
true.
|
||||||
* `-print0`: Outputs the file path, followed by a zero byte. Always evaluates to
|
* `-print0`: Outputs the file path, followed by a zero byte. Always evaluates to
|
||||||
|
|
|
@ -511,7 +511,27 @@ private:
|
||||||
return m_gid_range.contains(stat.st_gid);
|
return m_gid_range.contains(stat.st_gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumericRange<gid_t> m_gid_range;
|
NumericRange<gid_t> m_gid_range {};
|
||||||
|
};
|
||||||
|
|
||||||
|
class UidCommand final : public StatCommand {
|
||||||
|
public:
|
||||||
|
UidCommand(char const* arg)
|
||||||
|
{
|
||||||
|
auto uid_or_error = NumericRange<uid_t>::parse({ arg, strlen(arg) });
|
||||||
|
if (uid_or_error.is_error())
|
||||||
|
fatal_error("find: Invalid argument '{}' to '-uid'", arg);
|
||||||
|
|
||||||
|
m_uid_range = uid_or_error.release_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual bool evaluate(struct stat const& stat) const override
|
||||||
|
{
|
||||||
|
return m_uid_range.contains(stat.st_uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
NumericRange<uid_t> m_uid_range {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class PrintCommand final : public Command {
|
class PrintCommand final : public Command {
|
||||||
|
@ -737,6 +757,10 @@ static OwnPtr<Command> parse_simple_command(Vector<char*>& args)
|
||||||
if (args.is_empty())
|
if (args.is_empty())
|
||||||
fatal_error("-gid: requires additional arguments");
|
fatal_error("-gid: requires additional arguments");
|
||||||
return make<GidCommand>(args.take_first());
|
return make<GidCommand>(args.take_first());
|
||||||
|
} else if (arg == "-uid") {
|
||||||
|
if (args.is_empty())
|
||||||
|
fatal_error("-uid: requires additional arguments");
|
||||||
|
return make<UidCommand>(args.take_first());
|
||||||
} else if (arg == "-print") {
|
} else if (arg == "-print") {
|
||||||
g_have_seen_action_command = true;
|
g_have_seen_action_command = true;
|
||||||
return make<PrintCommand>();
|
return make<PrintCommand>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue