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

@@ -9,7 +9,6 @@
#include "util.h"
static int hflag = 0;
static int Rflag = 0;
static gid_t gid = -1;
static int ret = 0;
@@ -30,7 +29,7 @@ chgrp(const char *path, struct stat *st, void *data, struct recursor *r)
if (st && chownf(path, st->st_uid, gid) < 0) {
weprintf("%s %s:", chownf_name, 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);
}
}
@@ -45,14 +44,14 @@ int
main(int argc, char *argv[])
{
struct group *gr;
struct recursor r = { .fn = chgrp, .hist = NULL, .depth = 0, .follow = 'P', .flags = 0 };
struct recursor r = { .fn = chgrp, .hist = NULL, .depth = 0, .follow = 'P', .flags = NODIRS };
ARGBEGIN {
case 'h':
hflag = 1;
break;
case 'R':
Rflag = 1;
r.flags &= ~NODIRS;
break;
case 'H':
case 'L':