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

@@ -24,7 +24,7 @@ int cp_status = 0;
int cp_HLPflag = 'L';
int
cp(const char *s1, const char *s2, char ff)
cp(const char *s1, const char *s2, int depth)
{
FILE *f1, *f2;
char *ns1, *ns2;
@@ -39,9 +39,11 @@ cp(const char *s1, const char *s2, char ff)
if (cp_vflag)
printf("'%s' -> '%s'\n", s1, s2);
r = ff == 'P' ? lstat(s1, &st) : stat(s1, &st);
r = (cp_HLPflag == 'P' || (cp_HLPflag == 'H' && depth > 0)) ?
lstat(s1, &st) : stat(s1, &st);
if (r < 0) {
weprintf("%s %s:", ff == 'P' ? "lstat" : "stat", s1);
weprintf("%s %s:", (cp_HLPflag == 'P' ||
(cp_HLPflag == 'H' && depth > 0)) ? "lstat" : "stat", s1);
cp_status = 1;
return 0;
}
@@ -83,7 +85,7 @@ cp(const char *s1, const char *s2, char ff)
eprintf("%s/%s: filename too long\n",
s2, d->d_name);
}
fnck(ns1, ns2, cp, ff == 'H' ? 'P' : ff);
fnck(ns1, ns2, cp, depth + 1);
}
}
closedir(dp);