mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
rm: Allow empty paths if -f is specified
On most (if not all) systems rm ignores an empty paths array if -f or --force is specified. This helps with scripts that may pass an empty variable where the file paths are supposed to go.
This commit is contained in:
parent
aec941b46c
commit
f295ac3c0b
1 changed files with 6 additions and 1 deletions
|
@ -27,9 +27,14 @@ int main(int argc, char** argv)
|
|||
args_parser.add_option(recursive, "Delete directories recursively", "recursive", 'r');
|
||||
args_parser.add_option(force, "Force", "force", 'f');
|
||||
args_parser.add_option(verbose, "Verbose", "verbose", 'v');
|
||||
args_parser.add_positional_argument(paths, "Path(s) to remove", "path");
|
||||
args_parser.add_positional_argument(paths, "Path(s) to remove", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
if (!force && paths.is_empty()) {
|
||||
args_parser.print_usage(stderr, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool had_errors = false;
|
||||
for (auto& path : paths) {
|
||||
auto result = Core::File::remove(path, recursive ? Core::File::RecursionMode::Allowed : Core::File::RecursionMode::Disallowed, force);
|
||||
|
|
Loading…
Add table
Reference in a new issue