find: Add -gid
option to filter by owning group ID
This commit is contained in:
parent
d87fbcccb7
commit
d3da8f978e
Notes:
sideshowbarker
2024-07-16 22:18:54 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/d3da8f978e Pull-request: https://github.com/SerenityOS/serenity/pull/21004 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 26 additions and 0 deletions
|
@ -76,6 +76,8 @@ by the current user.
|
|||
the specified reference file. If `file` is a symbolic link and the `-L`
|
||||
option is in use, then the creation time of the file pointed to by the
|
||||
symbolic link is used.
|
||||
* `-gid [-|+]number`: Checks if the file is owned by a group with an ID less
|
||||
than, greater than or exactly `number`.
|
||||
* `-print`: Outputs the file path, followed by a newline. Always evaluates to
|
||||
true.
|
||||
* `-print0`: Outputs the file path, followed by a zero byte. Always evaluates to
|
||||
|
|
|
@ -494,6 +494,26 @@ private:
|
|||
TimestampType m_timestamp_type { TimestampType::LastModification };
|
||||
};
|
||||
|
||||
class GidCommand final : public StatCommand {
|
||||
public:
|
||||
GidCommand(char const* arg)
|
||||
{
|
||||
auto gid_or_error = NumericRange<gid_t>::parse({ arg, strlen(arg) });
|
||||
if (gid_or_error.is_error())
|
||||
fatal_error("find: Invalid argument '{}' to '-gid'", arg);
|
||||
|
||||
m_gid_range = gid_or_error.release_value();
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool evaluate(struct stat const& stat) const override
|
||||
{
|
||||
return m_gid_range.contains(stat.st_gid);
|
||||
}
|
||||
|
||||
NumericRange<gid_t> m_gid_range;
|
||||
};
|
||||
|
||||
class PrintCommand final : public Command {
|
||||
public:
|
||||
PrintCommand(char terminator = '\n')
|
||||
|
@ -713,6 +733,10 @@ static OwnPtr<Command> parse_simple_command(Vector<char*>& args)
|
|||
if (args.is_empty())
|
||||
fatal_error("-cnewer: requires additional arguments");
|
||||
return make<NewerCommand>(args.take_first(), NewerCommand::TimestampType::Creation);
|
||||
} else if (arg == "-gid") {
|
||||
if (args.is_empty())
|
||||
fatal_error("-gid: requires additional arguments");
|
||||
return make<GidCommand>(args.take_first());
|
||||
} else if (arg == "-print") {
|
||||
g_have_seen_action_command = true;
|
||||
return make<PrintCommand>();
|
||||
|
|
Loading…
Add table
Reference in a new issue