mirror of
git://git.suckless.org/sbase
synced 2026-01-26 13:43:17 +00:00
POSIX mandates that if the input of rm is a tty and it does not have write rights over a file/dir then it should ask for confirmation, in the same way that is done with the -i flag. To accomodate both things the code has been rearrenged a bit to have only one case instead of having two. Also, this rework adds the error message when a directory is removed without a -r flag.
45 lines
667 B
C
45 lines
667 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <fcntl.h>
|
|
|
|
#include "fs.h"
|
|
#include "util.h"
|
|
|
|
static void
|
|
usage(void)
|
|
{
|
|
eprintf("usage: %s [-f] [-iRr] file ...\n", argv0);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
struct recursor r = { .fn = rm, .maxdepth = 1, .follow = 'P' };
|
|
|
|
ARGBEGIN {
|
|
case 'f':
|
|
r.flags |= SILENT | IGNORE;
|
|
break;
|
|
case 'i':
|
|
r.flags |= CONFIRM;
|
|
break;
|
|
case 'R':
|
|
case 'r':
|
|
r.maxdepth = 0;
|
|
break;
|
|
default:
|
|
usage();
|
|
} ARGEND
|
|
|
|
if (!argc) {
|
|
if (!(r.flags & IGNORE))
|
|
usage();
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
for (; *argv; argc--, argv++)
|
|
recurse(AT_FDCWD, *argv, NULL, &r);
|
|
|
|
return rm_status || recurse_status;
|
|
}
|