sbase/libutil/rm.c
FRIGN e14d9412f8 Properly handle recursion in recurse()
The restructuring of recurse() in the last few weeks actually broke
the recursion-flags in different tools.
As a long-term goal, the recursor should have a field "maxdepth"
which should be "1" for the non-Rflag-case. "0" stands for unlimited.
2015-04-20 11:12:40 +01:00

33 lines
663 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_fflag = 0;
int rm_status = 0;
void
rm(const char *path, struct stat *st, void *data, struct recursor *r)
{
if (!(r->flags & NODIRS) && st && S_ISDIR(st->st_mode)) {
recurse(path, NULL, r);
if (rmdir(path) < 0) {
if (!rm_fflag)
weprintf("rmdir %s:", path);
if (!(rm_fflag && errno == ENOENT))
rm_status = 1;
}
} else if (unlink(path) < 0) {
if (!rm_fflag)
weprintf("unlink %s:", path);
if (!(rm_fflag && errno == ENOENT))
rm_status = 1;
}
}