diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-11-29 20:21:26 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-11-29 20:21:29 +0100 |
commit | 5a9d53c47e3c6ce5bc7d38c60501a37ce2c2b276 (patch) | |
tree | e04c756e01daa0e71a209a5ed60e464395268d85 /commands/rm.c | |
parent | 159109f5ff2e3b0ee7c44685e2241605ae41b662 (diff) | |
download | barebox-5a9d53c47e3c6ce5bc7d38c60501a37ce2c2b276.tar.gz |
rm: implement -r
To recursively remove files and directories.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/rm.c')
-rw-r--r-- | commands/rm.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/commands/rm.c b/commands/rm.c index 4e765acf7a..5486005d9b 100644 --- a/commands/rm.c +++ b/commands/rm.c @@ -19,17 +19,36 @@ #include <common.h> #include <command.h> #include <fs.h> +#include <getopt.h> #include <errno.h> static int do_rm(int argc, char *argv[]) { - int i = 1; + int i, opt, recursive = 0; + + while ((opt = getopt(argc, argv, "r")) > 0) { + switch (opt) { + case 'r': + recursive = 1; + break; + default: + return COMMAND_ERROR_USAGE; + } + } if (argc < 2) return COMMAND_ERROR_USAGE; + i = optind; + while (i < argc) { - if (unlink(argv[i])) { + int ret; + + if (recursive) + ret = unlink_recursive(argv[i], NULL); + else + ret = unlink(argv[i]); + if (ret) { printf("could not remove %s: %s\n", argv[i], errno_str()); return 1; } @@ -40,8 +59,9 @@ static int do_rm(int argc, char *argv[]) } static const __maybe_unused char cmd_rm_help[] = -"Usage: rm [FILES]\n" -"Remove files\n"; +"Usage: rm [OPTIONS] [FILES]\n" +"Remove files\n" +"-r remove directories and their contents recursively\n"; BAREBOX_CMD_START(rm) .cmd = do_rm, |