Skip to content

Commit

Permalink
find: Add -gid option to filter by owning group ID
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 authored and ADKaster committed Sep 17, 2023
1 parent d87fbcc commit d3da8f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Base/usr/share/man/man1/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions Userland/Utilities/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,26 @@ class NewerCommand final : public StatCommand {
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')
Expand Down Expand Up @@ -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>();
Expand Down

0 comments on commit d3da8f9

Please sign in to comment.