[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Mini rm implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* BB_AUDIT SUSv3 compliant */
|
---|
| 11 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
|
---|
| 12 |
|
---|
| 13 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
---|
| 14 | *
|
---|
| 15 | * Size reduction.
|
---|
| 16 | */
|
---|
| 17 |
|
---|
[3232] | 18 | //usage:#define rm_trivial_usage
|
---|
| 19 | //usage: "[-irf] FILE..."
|
---|
| 20 | //usage:#define rm_full_usage "\n\n"
|
---|
| 21 | //usage: "Remove (unlink) FILEs\n"
|
---|
| 22 | //usage: "\n -i Always prompt before removing"
|
---|
| 23 | //usage: "\n -f Never prompt"
|
---|
| 24 | //usage: "\n -R,-r Recurse"
|
---|
| 25 | //usage:
|
---|
| 26 | //usage:#define rm_example_usage
|
---|
| 27 | //usage: "$ rm -rf /tmp/foo\n"
|
---|
| 28 |
|
---|
[1765] | 29 | #include "libbb.h"
|
---|
[821] | 30 |
|
---|
[1765] | 31 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 32 |
|
---|
[2725] | 33 | int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 34 | int rm_main(int argc UNUSED_PARAM, char **argv)
|
---|
[821] | 35 | {
|
---|
| 36 | int status = 0;
|
---|
| 37 | int flags = 0;
|
---|
[1765] | 38 | unsigned opt;
|
---|
[821] | 39 |
|
---|
[1765] | 40 | opt_complementary = "f-i:i-f";
|
---|
[2725] | 41 | /* -v (verbose) is ignored */
|
---|
| 42 | opt = getopt32(argv, "fiRrv");
|
---|
[1765] | 43 | argv += optind;
|
---|
| 44 | if (opt & 1)
|
---|
| 45 | flags |= FILEUTILS_FORCE;
|
---|
| 46 | if (opt & 2)
|
---|
[821] | 47 | flags |= FILEUTILS_INTERACTIVE;
|
---|
[2725] | 48 | if (opt & (8|4))
|
---|
[821] | 49 | flags |= FILEUTILS_RECUR;
|
---|
| 50 |
|
---|
[1765] | 51 | if (*argv != NULL) {
|
---|
[821] | 52 | do {
|
---|
[2725] | 53 | const char *base = bb_get_last_path_component_strip(*argv);
|
---|
[821] | 54 |
|
---|
[1765] | 55 | if (DOT_OR_DOTDOT(base)) {
|
---|
[2725] | 56 | bb_error_msg("can't remove '.' or '..'");
|
---|
[821] | 57 | } else if (remove_file(*argv, flags) >= 0) {
|
---|
| 58 | continue;
|
---|
| 59 | }
|
---|
| 60 | status = 1;
|
---|
| 61 | } while (*++argv);
|
---|
| 62 | } else if (!(flags & FILEUTILS_FORCE)) {
|
---|
| 63 | bb_show_usage();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | return status;
|
---|
| 67 | }
|
---|