Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/recursive_action.c

    r1765 r2725  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    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.
    88 */
    99
     
    2323 */
    2424
    25 static int true_action(const char *fileName, struct stat *statbuf,
    26                         void* userData, int depth)
     25static 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)
    2729{
    2830    return TRUE;
     
    3335 * (fileAction/dirAction will be called on each file).
    3436 *
    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.
    3839 *
    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.
    4052 * 0: lstat(statbuf). Calls fileAction on link name even if points to dir.
    4153 * 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir.
    4254 */
    4355
    44 int recursive_action(const char *fileName,
     56int FAST_FUNC recursive_action(const char *fileName,
    4557        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),
    4860        void* userData,
    4961        unsigned depth)
    5062{
    5163    struct stat statbuf;
     64    unsigned follow;
    5265    int status;
    5366    DIR *dir;
     
    5770    if (!dirAction) dirAction = true_action;
    5871
    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);
    6277    if (status < 0) {
    6378#ifdef DEBUG_RECURS_ACTION
    6479        bb_error_msg("status=%d flags=%x", status, flags);
    6580#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        }
    6688        goto done_nak_warn;
    6789    }
     
    104126        if (nextFile == NULL)
    105127            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))
    108131            status = FALSE;
     132//      s = recursive_action(nextFile, flags, fileAction, dirAction,
     133//                      userData, depth + 1);
    109134        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;
    110142    }
    111143    closedir(dir);
     
    116148    }
    117149
    118     if (!status)
    119         return FALSE;
    120     return TRUE;
     150    return status;
    121151
    122152 done_nak_warn:
    123     bb_perror_msg("%s", fileName);
     153    if (!(flags & ACTION_QUIET))
     154        bb_simple_perror_msg(fileName);
    124155    return FALSE;
    125156}
Note: See TracChangeset for help on using the changeset viewer.