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.
This commit is contained in:
FRIGN
2015-03-02 21:43:56 +01:00
parent 274e86e1aa
commit 8dc92fbd6c
13 changed files with 71 additions and 59 deletions

View File

@@ -4,13 +4,12 @@
#include "util.h"
static int Rflag = 0;
static int fflag = 'P';
static char *modestr = "";
static mode_t mask = 0;
static int ret = 0;
void
chmodr(const char *path, int fflag)
chmodr(const char *path, int depth)
{
struct stat st;
mode_t m;
@@ -27,7 +26,7 @@ chmodr(const char *path, int fflag)
ret = 1;
}
if (Rflag)
recurse(path, chmodr, fflag);
recurse(path, chmodr, depth);
}
static void
@@ -50,7 +49,7 @@ main(int argc, char *argv[])
case 'H':
case 'L':
case 'P':
fflag = argv[i][1];
recurse_follow = argv[i][1];
break;
case 'r': case 'w': case 'x': case 's': case 't':
/*
@@ -71,7 +70,7 @@ done:
usage();
for (++i; i < argc; i++)
chmodr(argv[i], fflag);
chmodr(argv[i], 0);
return ret;
}