mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
rm: Check before removing '/'
A simple check to not erase '/' by mistake.
This commit is contained in:
parent
416033a660
commit
4d557a4b81
Notes:
sideshowbarker
2024-07-17 21:47:42 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/4d557a4b81f Pull-request: https://github.com/SerenityOS/serenity/pull/11565 Reviewed-by: https://github.com/IdanHo
1 changed files with 8 additions and 1 deletions
|
@ -21,12 +21,14 @@ int main(int argc, char** argv)
|
|||
bool recursive = false;
|
||||
bool force = false;
|
||||
bool verbose = false;
|
||||
Vector<const char*> paths;
|
||||
bool no_preserve_root = false;
|
||||
Vector<StringView> paths;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
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_option(no_preserve_root, "Do not consider '/' specially", "no-preserve-root", 0);
|
||||
args_parser.add_positional_argument(paths, "Path(s) to remove", "path", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
|
@ -37,6 +39,11 @@ int main(int argc, char** argv)
|
|||
|
||||
bool had_errors = false;
|
||||
for (auto& path : paths) {
|
||||
if (!no_preserve_root && path == "/") {
|
||||
warnln("rm: '/' is protected, try with --no-preserve-root to override this behavior");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto result = Core::File::remove(path, recursive ? Core::File::RecursionMode::Allowed : Core::File::RecursionMode::Disallowed, force);
|
||||
|
||||
if (result.is_error()) {
|
||||
|
|
Loading…
Reference in a new issue