summaryrefslogtreecommitdiff
path: root/Userland/Utilities/rm.cpp
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2021-06-05 03:08:02 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-05 10:56:58 +0200
commitf295ac3c0bc2625366bf5ada3e7413b1bcc9fb22 (patch)
tree549b43dfb478bcd013af1d0b8cbc248cbb0526ce /Userland/Utilities/rm.cpp
parentaec941b46cd9f38690f4e7d9368a300d17776820 (diff)
downloadserenity-f295ac3c0bc2625366bf5ada3e7413b1bcc9fb22.zip
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.
Diffstat (limited to 'Userland/Utilities/rm.cpp')
-rw-r--r--Userland/Utilities/rm.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Utilities/rm.cpp b/Userland/Utilities/rm.cpp
index 97e24ae506..c1650aa12b 100644
--- a/Userland/Utilities/rm.cpp
+++ b/Userland/Utilities/rm.cpp
@@ -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);