mirror of
git://git.suckless.org/sbase
synced 2024-12-23 23:43:33 +00:00
f83d7bc647
recurse() is getting smarter every day. I expect it to pass the Turing test in a few months. Along the way, it was reported that "rm -f" on nonexistant files reports their missing as an internal recurse()-error. So recurse() knows when to shut up, I added the SILENT flag to fix all these things.
32 lines
681 B
C
32 lines
681 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include "../fs.h"
|
|
#include "../util.h"
|
|
|
|
int rm_status = 0;
|
|
|
|
void
|
|
rm(const char *path, struct stat *st, void *data, struct recursor *r)
|
|
{
|
|
if (!r->maxdepth && st && S_ISDIR(st->st_mode)) {
|
|
recurse(path, NULL, r);
|
|
|
|
if (rmdir(path) < 0) {
|
|
if (!(r->flags & SILENT))
|
|
weprintf("rmdir %s:", path);
|
|
if (!((r->flags & SILENT) && errno == ENOENT))
|
|
rm_status = 1;
|
|
}
|
|
} else if (unlink(path) < 0) {
|
|
if (!(r->flags & SILENT))
|
|
weprintf("unlink %s:", path);
|
|
if (!((r->flags & SILENT) && errno == ENOENT))
|
|
rm_status = 1;
|
|
}
|
|
}
|