Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini rm implementation for busybox |
| 4 | * |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu> |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 6 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 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 | |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 18 | #include <unistd.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 19 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 20 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 21 | int rm_main(int argc, char **argv) |
Eric Andersen | bed30e9 | 1999-10-18 19:02:32 +0000 | [diff] [blame] | 22 | { |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 23 | int status = 0; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 24 | int flags = 0; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 25 | unsigned opt; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 27 | opt_complementary = "f-i:i-f"; |
| 28 | opt = getopt32(argc, argv, "fiRr"); |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 29 | if(opt & 1) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 30 | flags |= FILEUTILS_FORCE; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 31 | if(opt & 2) |
| 32 | flags |= FILEUTILS_INTERACTIVE; |
| 33 | if(opt & 12) |
| 34 | flags |= FILEUTILS_RECUR; |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 35 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 36 | if (*(argv += optind) != NULL) { |
| 37 | do { |
| 38 | const char *base = bb_get_last_path_component(*argv); |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 39 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 40 | if ((base[0] == '.') && (!base[1] || ((base[1] == '.') && !base[2]))) { |
Denis Vlasenko | 89f0b34 | 2006-11-18 22:04:09 +0000 | [diff] [blame] | 41 | bb_error_msg("cannot remove '.' or '..'"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 42 | } else if (remove_file(*argv, flags) >= 0) { |
| 43 | continue; |
| 44 | } |
Matt Kraai | 8810bdb | 2001-04-24 20:04:18 +0000 | [diff] [blame] | 45 | status = 1; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 46 | } while (*++argv); |
| 47 | } else if (!(flags & FILEUTILS_FORCE)) { |
| 48 | bb_show_usage(); |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 49 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 50 | |
Matt Kraai | d27753a | 2000-12-05 05:11:41 +0000 | [diff] [blame] | 51 | return status; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 52 | } |