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/make_directory.c

    r1765 r2725  
    55 * Copyright (C) 2003  Manuel Novoa III  <mjn3@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
     
    2727/* This function is used from NOFORK applets. It must not allocate anything */
    2828
    29 int bb_make_directory (char *path, long mode, int flags)
     29int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
    3030{
    31     mode_t mask;
     31    mode_t cur_mask;
     32    mode_t org_mask;
    3233    const char *fail_msg;
    33     char *s = path;
     34    char *s;
    3435    char c;
    3536    struct stat st;
    3637
    37     mask = umask(0);
    38     if (mode == -1) {
    39         umask(mask);
    40         mode = (S_IXUSR | S_IXGRP | S_IXOTH |
    41                 S_IWUSR | S_IWGRP | S_IWOTH |
    42                 S_IRUSR | S_IRGRP | S_IROTH) & ~mask;
    43     } else {
    44         umask(mask & ~0300);
    45     }
     38    /* Happens on bb_make_directory(dirname("no_slashes"),...) */
     39    if (LONE_CHAR(path, '.'))
     40        return 0;
    4641
    47     do {
    48         c = 0;
     42    org_mask = cur_mask = (mode_t)-1L;
     43    s = path;
     44    while (1) {
     45        c = '\0';
    4946
    50         if (flags & FILEUTILS_RECUR) {  /* Get the parent. */
    51             /* Bypass leading non-'/'s and then subsequent '/'s. */
     47        if (flags & FILEUTILS_RECUR) {  /* Get the parent */
     48            /* Bypass leading non-'/'s and then subsequent '/'s */
    5249            while (*s) {
    5350                if (*s == '/') {
     
    5552                        ++s;
    5653                    } while (*s == '/');
    57                     c = *s;     /* Save the current char */
    58                     *s = 0;     /* and replace it with nul. */
     54                    c = *s; /* Save the current char */
     55                    *s = '\0'; /* and replace it with nul */
    5956                    break;
    6057                }
     
    6360        }
    6461
     62        if (c != '\0') {
     63            /* Intermediate dirs: must have wx for user */
     64            if (cur_mask == (mode_t)-1L) { /* wasn't done yet? */
     65                mode_t new_mask;
     66                org_mask = umask(0);
     67                cur_mask = 0;
     68                /* Clear u=wx in umask - this ensures
     69                 * they won't be cleared on mkdir */
     70                new_mask = (org_mask & ~(mode_t)0300);
     71                //bb_error_msg("org_mask:%o cur_mask:%o", org_mask, new_mask);
     72                if (new_mask != cur_mask) {
     73                    cur_mask = new_mask;
     74                    umask(new_mask);
     75                }
     76            }
     77        } else {
     78            /* Last component: uses original umask */
     79            //bb_error_msg("1 org_mask:%o", org_mask);
     80            if (org_mask != cur_mask) {
     81                cur_mask = org_mask;
     82                umask(org_mask);
     83            }
     84        }
     85
    6586        if (mkdir(path, 0777) < 0) {
    6687            /* If we failed for any other reason than the directory
    67              * already exists, output a diagnostic and return -1.*/
    68             if (errno != EEXIST
    69                 || !(flags & FILEUTILS_RECUR)
    70                 || (stat(path, &st) < 0 || !S_ISDIR(st.st_mode))) {
     88             * already exists, output a diagnostic and return -1 */
     89            if ((errno != EEXIST && errno != EISDIR)
     90             || !(flags & FILEUTILS_RECUR)
     91             || ((stat(path, &st) < 0) || !S_ISDIR(st.st_mode))
     92            ) {
    7193                fail_msg = "create";
    72                 umask(mask);
    7394                break;
    7495            }
    7596            /* Since the directory exists, don't attempt to change
    7697             * permissions if it was the full target.  Note that
    77              * this is not an error conditon. */
     98             * this is not an error condition. */
    7899            if (!c) {
    79                 umask(mask);
    80                 return 0;
     100                goto ret0;
    81101            }
    82102        }
    83103
    84104        if (!c) {
    85             /* Done.  If necessary, updated perms on the newly
     105            /* Done.  If necessary, update perms on the newly
    86106             * created directory.  Failure to update here _is_
    87              * an error.*/
    88             umask(mask);
    89             if ((mode != -1) && (chmod(path, mode) < 0)){
     107             * an error. */
     108            if ((mode != -1) && (chmod(path, mode) < 0)) {
    90109                fail_msg = "set permissions of";
    91110                break;
    92111            }
    93             return 0;
     112            goto ret0;
    94113        }
    95114
    96         /* Remove any inserted nul from the path (recursive mode). */
     115        /* Remove any inserted nul from the path (recursive mode) */
    97116        *s = c;
     117    } /* while (1) */
    98118
    99     } while (1);
    100 
    101     bb_perror_msg("cannot %s directory '%s'", fail_msg, path);
    102     return -1;
     119    bb_perror_msg("can't %s directory '%s'", fail_msg, path);
     120    flags = -1;
     121    goto ret;
     122 ret0:
     123    flags = 0;
     124 ret:
     125    //bb_error_msg("2 org_mask:%o", org_mask);
     126    if (org_mask != cur_mask)
     127        umask(org_mask);
     128    return flags;
    103129}
Note: See TracChangeset for help on using the changeset viewer.