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.
This commit is contained in:
FRIGN
2015-04-18 21:24:17 +02:00
committed by sin
parent e2edbdcb87
commit e14d9412f8
8 changed files with 24 additions and 20 deletions

View File

@@ -4,7 +4,6 @@
#include "fs.h"
#include "util.h"
static int Rflag = 0;
static char *modestr = "";
static mode_t mask = 0;
static int ret = 0;
@@ -18,7 +17,7 @@ chmodr(const char *path, struct stat *st, void *data, struct recursor *r)
if (chmod(path, m) < 0) {
weprintf("chmod %s:", path);
ret = 1;
} else if (Rflag && st && S_ISDIR(st->st_mode)) {
} else if (!(r->flags & NODIRS) && st && S_ISDIR(st->st_mode)) {
recurse(path, NULL, r);
}
}
@@ -32,7 +31,7 @@ usage(void)
int
main(int argc, char *argv[])
{
struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0};
struct recursor r = { .fn = chmodr, .hist = NULL, .depth = 0, .follow = 'P', .flags = NODIRS};
size_t i;
argv0 = argv[0], argc--, argv++;
@@ -43,7 +42,7 @@ main(int argc, char *argv[])
for (i = 1; (*argv)[i]; i++) {
switch ((*argv)[i]) {
case 'R':
Rflag = 1;
r.flags &= ~NODIRS;
break;
case 'H':
case 'L':