summaryrefslogtreecommitdiff
path: root/libbb/recursive_action.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/recursive_action.c')
-rw-r--r--libbb/recursive_action.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c
index be2a700f5..cb3b88d1d 100644
--- a/libbb/recursive_action.c
+++ b/libbb/recursive_action.c
@@ -46,7 +46,7 @@ int recursive_action(const char *fileName,
46 int (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth), 46 int (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
47 int (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth), 47 int (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
48 void* userData, 48 void* userData,
49 const unsigned depth) 49 unsigned depth)
50{ 50{
51 struct stat statbuf; 51 struct stat statbuf;
52 int status; 52 int status;
@@ -55,12 +55,13 @@ int recursive_action(const char *fileName,
55 55
56 if (!fileAction) fileAction = true_action; 56 if (!fileAction) fileAction = true_action;
57 if (!dirAction) dirAction = true_action; 57 if (!dirAction) dirAction = true_action;
58 status = (flags & ACTION_FOLLOWLINKS ? stat : lstat)(fileName, &statbuf);
59 58
59 status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */
60 if (!depth) status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0;
61 status = ((flags & status) ? stat : lstat)(fileName, &statbuf);
60 if (status < 0) { 62 if (status < 0) {
61#ifdef DEBUG_RECURS_ACTION 63#ifdef DEBUG_RECURS_ACTION
62 bb_error_msg("status=%d followLinks=%d TRUE=%d", 64 bb_error_msg("status=%d flags=%x", status, flags);
63 status, flags & ACTION_FOLLOWLINKS, TRUE);
64#endif 65#endif
65 goto done_nak_warn; 66 goto done_nak_warn;
66 } 67 }
@@ -82,9 +83,8 @@ int recursive_action(const char *fileName,
82 83
83 if (!(flags & ACTION_DEPTHFIRST)) { 84 if (!(flags & ACTION_DEPTHFIRST)) {
84 status = dirAction(fileName, &statbuf, userData, depth); 85 status = dirAction(fileName, &statbuf, userData, depth);
85 if (!status) { 86 if (!status)
86 goto done_nak_warn; 87 goto done_nak_warn;
87 }
88 if (status == SKIP) 88 if (status == SKIP)
89 return TRUE; 89 return TRUE;
90 } 90 }
@@ -103,23 +103,23 @@ int recursive_action(const char *fileName,
103 nextFile = concat_subpath_file(fileName, next->d_name); 103 nextFile = concat_subpath_file(fileName, next->d_name);
104 if (nextFile == NULL) 104 if (nextFile == NULL)
105 continue; 105 continue;
106 /* now descend into it, forcing recursion. */ 106 /* now descend into it (NB: ACTION_RECURSE is set in flags) */
107 if (!recursive_action(nextFile, flags | ACTION_RECURSE, 107 if (!recursive_action(nextFile, flags, fileAction, dirAction, userData, depth+1))
108 fileAction, dirAction, userData, depth+1)) {
109 status = FALSE; 108 status = FALSE;
110 }
111 free(nextFile); 109 free(nextFile);
112 } 110 }
113 closedir(dir); 111 closedir(dir);
114 if ((flags & ACTION_DEPTHFIRST) && 112
115 !dirAction(fileName, &statbuf, userData, depth)) { 113 if (flags & ACTION_DEPTHFIRST) {
114 if (!dirAction(fileName, &statbuf, userData, depth))
116 goto done_nak_warn; 115 goto done_nak_warn;
117 } 116 }
118 117
119 if (!status) 118 if (!status)
120 return FALSE; 119 return FALSE;
121 return TRUE; 120 return TRUE;
122done_nak_warn: 121
122 done_nak_warn:
123 bb_perror_msg("%s", fileName); 123 bb_perror_msg("%s", fileName);
124 return FALSE; 124 return FALSE;
125} 125}