sbase/libutil/rm.c
FRIGN 8dc92fbd6c Refactor enmasse() and recurse() to reflect depth
The HLP-changes to sbase have been a great addition of functionality,
but they kind of "polluted" the enmasse() and recurse() prototypes.
As this will come in handy in the future, knowing at which "depth"
you are inside a recursing function is an important functionality.

Instead of having a special HLP-flag passed to enmasse, each sub-
function needs to provide it on its own and can calculate results
based on the current depth (for instance, 'H' implies 'P' at
depth > 0).
A special case is recurse(), because it actually depends on the
follow-type. A new flag "recurse_follow" brings consistency into
what used to be spread across different naming conventions (fflag,
HLP_flag, ...).

This also fixes numerous bugs with the behaviour of HLP in the
tools using it.
2015-03-02 22:50:38 +01:00

24 lines
412 B
C

/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <stdio.h>
#include "../fs.h"
#include "../util.h"
int rm_fflag = 0;
int rm_rflag = 0;
int rm_status = 0;
void
rm(const char *path, int depth)
{
if (rm_rflag)
recurse(path, rm, depth);
if (remove(path) < 0) {
if (!rm_fflag)
weprintf("remove %s:", path);
if (!(rm_fflag && errno == ENOENT))
rm_status = 1;
}
}