48 |
* into that directory, instead recursive_action() returns 0 (if FALSE) |
* into that directory, instead recursive_action() returns 0 (if FALSE) |
49 |
* or 1 (if SKIP) |
* or 1 (if SKIP) |
50 |
* |
* |
51 |
* followLinks=0/1 differs mainly in handling of links to dirs. |
* ACTION_FOLLOWLINKS mainly controls handling of links to dirs. |
52 |
* 0: lstat(statbuf). Calls fileAction on link name even if points to dir. |
* 0: lstat(statbuf). Calls fileAction on link name even if points to dir. |
53 |
* 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir. |
* 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir. |
54 |
*/ |
*/ |
61 |
unsigned depth) |
unsigned depth) |
62 |
{ |
{ |
63 |
struct stat statbuf; |
struct stat statbuf; |
64 |
|
unsigned follow; |
65 |
int status; |
int status; |
66 |
DIR *dir; |
DIR *dir; |
67 |
struct dirent *next; |
struct dirent *next; |
69 |
if (!fileAction) fileAction = true_action; |
if (!fileAction) fileAction = true_action; |
70 |
if (!dirAction) dirAction = true_action; |
if (!dirAction) dirAction = true_action; |
71 |
|
|
72 |
status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */ |
follow = ACTION_FOLLOWLINKS; |
73 |
if (!depth) |
if (depth == 0) |
74 |
status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; |
follow = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; |
75 |
status = ((flags & status) ? stat : lstat)(fileName, &statbuf); |
follow &= flags; |
76 |
|
status = (follow ? stat : lstat)(fileName, &statbuf); |
77 |
if (status < 0) { |
if (status < 0) { |
78 |
#ifdef DEBUG_RECURS_ACTION |
#ifdef DEBUG_RECURS_ACTION |
79 |
bb_error_msg("status=%d flags=%x", status, flags); |
bb_error_msg("status=%d flags=%x", status, flags); |
80 |
#endif |
#endif |
81 |
|
if ((flags & ACTION_DANGLING_OK) |
82 |
|
&& errno == ENOENT |
83 |
|
&& lstat(fileName, &statbuf) == 0 |
84 |
|
) { |
85 |
|
/* Dangling link */ |
86 |
|
return fileAction(fileName, &statbuf, userData, depth); |
87 |
|
} |
88 |
goto done_nak_warn; |
goto done_nak_warn; |
89 |
} |
} |
90 |
|
|