Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/coreutils/install.c

    r3232 r3621  
    99/* -v, -b, -c are ignored */
    1010//usage:#define install_trivial_usage
    11 //usage:    "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
     11//usage:    "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
    1212//usage:#define install_full_usage "\n\n"
    1313//usage:       "Copy files and set attributes\n"
     
    2020//usage:     "\n    -g GRP  Set group ownership"
    2121//usage:     "\n    -m MODE Set permissions"
     22//usage:     "\n    -t DIR  Install to DIR"
    2223//usage:    IF_SELINUX(
    2324//usage:     "\n    -Z  Set security context"
     
    2930#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
    3031static const char install_longopts[] ALIGN1 =
     32    IF_FEATURE_VERBOSE(
     33    "verbose\0"             No_argument       "v"
     34    )
    3135    "directory\0"           No_argument       "d"
    3236    "preserve-timestamps\0" No_argument       "p"
     
    3539    "mode\0"                Required_argument "m"
    3640    "owner\0"               Required_argument "o"
     41    "target-directory\0"    Required_argument "t"
    3742/* autofs build insists of using -b --suffix=.orig */
    3843/* TODO? (short option for --suffix is -S) */
     
    9095    const char *uid_str;
    9196    const char *mode_str;
     97    int mkdir_flags = FILEUTILS_RECUR;
    9298    int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
    9399    int opts;
    94     int min_args = 1;
    95100    int ret = EXIT_SUCCESS;
    96     int isdir = 0;
     101    int isdir;
    97102#if ENABLE_SELINUX
    98103    security_context_t scontext;
     
    110115        OPT_MODE          = 1 << 8,
    111116        OPT_OWNER         = 1 << 9,
    112 #if ENABLE_SELINUX
    113         OPT_SET_SECURITY_CONTEXT = 1 << 10,
    114         OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
     117        OPT_TARGET        = 1 << 10,
     118#if ENABLE_SELINUX
     119        OPT_SET_SECURITY_CONTEXT = 1 << 11,
     120        OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
    115121#endif
    116122    };
     
    119125    applet_long_options = install_longopts;
    120126#endif
    121     opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
     127    opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
    122128    /* -c exists for backwards compatibility, it's needed */
    123     /* -v is ignored ("print name of each created directory") */
    124129    /* -b is ignored ("make a backup of each existing destination file") */
    125     opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
    126             &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
     130    opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
     131            &gid_str, &mode_str, &uid_str, &last
     132            IF_SELINUX(, &scontext));
    127133    argc -= optind;
    128134    argv += optind;
     
    142148#endif
    143149
     150    if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
     151        mkdir_flags |= FILEUTILS_VERBOSE;
     152        copy_flags |= FILEUTILS_VERBOSE;
     153    }
     154
    144155    /* preserve access and modification time, this is GNU behaviour,
    145156     * BSD only preserves modification time */
     
    149160    mode = 0755; /* GNU coreutils 6.10 compat */
    150161    if (opts & OPT_MODE)
    151         bb_parse_mode(mode_str, &mode);
     162        mode = bb_parse_mode(mode_str, mode);
    152163    uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
    153164    gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
    154165
    155     last = argv[argc - 1];
    156     if (!(opts & OPT_DIRECTORY)) {
    157         argv[argc - 1] = NULL;
    158         min_args++;
    159 
     166    /* If -t DIR is in use, then isdir=true, last="DIR" */
     167    isdir = (opts & OPT_TARGET);
     168    if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
     169        /* Neither -t DIR nor -d is in use */
     170        argc--;
     171        last = argv[argc];
     172        argv[argc] = NULL;
    160173        /* coreutils install resolves link in this case, don't use lstat */
    161174        isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
    162175    }
    163176
    164     if (argc < min_args)
     177    if (argc < 1)
    165178        bb_show_usage();
    166179
    167180    while ((arg = *argv++) != NULL) {
    168         char *dest = last;
     181        char *dest;
     182
    169183        if (opts & OPT_DIRECTORY) {
    170184            dest = arg;
     
    172186             * on intermediate created directories
    173187             * (only on last one) */
    174             if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
     188            if (bb_make_directory(dest, 0755, mkdir_flags)) {
    175189                ret = EXIT_FAILURE;
    176190                goto next;
    177191            }
    178192        } else {
     193            dest = last;
    179194            if (opts & OPT_MKDIR_LEADING) {
    180195                char *ddir = xstrdup(dest);
    181                 bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
     196                bb_make_directory(dirname(ddir), 0755, mkdir_flags);
    182197                /* errors are not checked. copy_file
    183198                 * will fail if dir is not created. */
Note: See TracChangeset for help on using the changeset viewer.