Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/recursive_action.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/recursive_action.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 23 23 */ 24 24 25 static int true_action(const char *fileName, struct stat *statbuf, 26 void* userData, int depth) 25 static int FAST_FUNC true_action(const char *fileName UNUSED_PARAM, 26 struct stat *statbuf UNUSED_PARAM, 27 void* userData UNUSED_PARAM, 28 int depth UNUSED_PARAM) 27 29 { 28 30 return TRUE; … … 33 35 * (fileAction/dirAction will be called on each file). 34 36 * 35 * if !depthFirst, dirAction return value of 0 (FALSE) or 2 (SKIP) 36 * prevents recursion into that directory, instead 37 * recursive_action() returns 0 (if FALSE) or 1 (if SKIP). 37 * If !ACTION_RECURSE, dirAction is called on the directory and its 38 * return value is returned from recursive_action(). No recursion. 38 39 * 39 * followLinks=0/1 differs mainly in handling of links to dirs. 40 * If ACTION_RECURSE, recursive_action() is called on each directory. 41 * If any one of these calls returns 0, current recursive_action() returns 0. 42 * 43 * If ACTION_DEPTHFIRST, dirAction is called after recurse. 44 * If it returns 0, the warning is printed and recursive_action() returns 0. 45 * 46 * If !ACTION_DEPTHFIRST, dirAction is called before we recurse. 47 * Return value of 0 (FALSE) or 2 (SKIP) prevents recursion 48 * into that directory, instead recursive_action() returns 0 (if FALSE) 49 * or 1 (if SKIP) 50 * 51 * ACTION_FOLLOWLINKS mainly controls handling of links to dirs. 40 52 * 0: lstat(statbuf). Calls fileAction on link name even if points to dir. 41 53 * 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir. 42 54 */ 43 55 44 int recursive_action(const char *fileName,56 int FAST_FUNC recursive_action(const char *fileName, 45 57 unsigned flags, 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),58 int FAST_FUNC (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth), 59 int FAST_FUNC (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth), 48 60 void* userData, 49 61 unsigned depth) 50 62 { 51 63 struct stat statbuf; 64 unsigned follow; 52 65 int status; 53 66 DIR *dir; … … 57 70 if (!dirAction) dirAction = true_action; 58 71 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); 72 follow = ACTION_FOLLOWLINKS; 73 if (depth == 0) 74 follow = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; 75 follow &= flags; 76 status = (follow ? stat : lstat)(fileName, &statbuf); 62 77 if (status < 0) { 63 78 #ifdef DEBUG_RECURS_ACTION 64 79 bb_error_msg("status=%d flags=%x", status, flags); 65 80 #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 } 66 88 goto done_nak_warn; 67 89 } … … 104 126 if (nextFile == NULL) 105 127 continue; 106 /* now descend into it (NB: ACTION_RECURSE is set in flags) */ 107 if (!recursive_action(nextFile, flags, fileAction, dirAction, userData, depth+1)) 128 /* process every file (NB: ACTION_RECURSE is set in flags) */ 129 if (!recursive_action(nextFile, flags, fileAction, dirAction, 130 userData, depth + 1)) 108 131 status = FALSE; 132 // s = recursive_action(nextFile, flags, fileAction, dirAction, 133 // userData, depth + 1); 109 134 free(nextFile); 135 //#define RECURSE_RESULT_ABORT 3 136 // if (s == RECURSE_RESULT_ABORT) { 137 // closedir(dir); 138 // return s; 139 // } 140 // if (s == FALSE) 141 // status = FALSE; 110 142 } 111 143 closedir(dir); … … 116 148 } 117 149 118 if (!status) 119 return FALSE; 120 return TRUE; 150 return status; 121 151 122 152 done_nak_warn: 123 bb_perror_msg("%s", fileName); 153 if (!(flags & ACTION_QUIET)) 154 bb_simple_perror_msg(fileName); 124 155 return FALSE; 125 156 }
Note:
See TracChangeset
for help on using the changeset viewer.