blob: 8c20c5e11cc9899754b9956653de673864819298 [file] [log] [blame]
Denys Vlasenkoab77e812017-08-18 19:15:29 +02001/*
2 * Copyright (c) 2017 Denys Vlasenko <vda.linux@googlemail.com>
3 *
Denys Vlasenkof41ffff2017-08-29 19:44:45 +02004 * Licensed under GPLv2, see file LICENSE in this source tree.
Denys Vlasenkoab77e812017-08-18 19:15:29 +02005 */
6//config:config NUKE
Denys Vlasenkob097a842018-12-28 03:20:17 +01007//config: bool "nuke (2.9 kb)"
Denys Vlasenko8b085d62021-01-03 16:48:53 +01008//config: default n # off by default: too "accidentally destructive"
Denys Vlasenkoab77e812017-08-18 19:15:29 +02009//config: help
10//config: Alias to "rm -rf".
11
12//applet:IF_NUKE(APPLET_NOEXEC(nuke, nuke, BB_DIR_BIN, BB_SUID_DROP, nuke))
13
14//kbuild:lib-$(CONFIG_NUKE) += nuke.o
15
16//usage:#define nuke_trivial_usage
17//usage: "DIR..."
18//usage:#define nuke_full_usage "\n\n"
Denys Vlasenko20c0d072017-08-18 19:23:51 +020019//usage: "Remove DIRs"
Denys Vlasenkoab77e812017-08-18 19:15:29 +020020
21#include "libbb.h"
22
23/* This is a NOEXEC applet. Be very careful! */
24
25int nuke_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
26int nuke_main(int argc UNUSED_PARAM, char **argv)
27{
28// klibc-utils do not check opts, will try to delete "-dir" args
29 //opt = getopt32(argv, "");
30 //argv += optind;
31
32 while (*++argv) {
33#if 0
34// klibc-utils do not check this, will happily operate on ".."
35 const char *base = bb_get_last_path_component_strip(*argv);
36 if (DOT_OR_DOTDOT(base)) {
37 bb_error_msg("can't remove '.' or '..'");
38 continue;
39 }
40#endif
41 remove_file(*argv, FILEUTILS_FORCE | FILEUTILS_RECUR);
42 }
43
44// klibc-utils do not indicate errors
45 return EXIT_SUCCESS;
46}