Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/coreutils/mv.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/mv.c

    r821 r1765  
    44 *
    55 * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
     6 * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
    67 *
    7  * This program is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    15  * General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    20  *
     8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    219 */
    2210
     
    2816#include <sys/types.h>
    2917#include <sys/stat.h>
    30 #include <unistd.h>
    3118#include <dirent.h>
    32 #include <errno.h>
    33 #include <stdlib.h>
    3419#include <getopt.h> /* struct option */
    35 #include "busybox.h"
     20#include "libbb.h"
    3621#include "libcoreutils/coreutils.h"
    3722
    3823#if ENABLE_FEATURE_MV_LONG_OPTIONS
    39 static const struct option mv_long_options[] = {
    40     { "interactive", 0, NULL, 'i' },
    41     { "force", 0, NULL, 'f' },
    42     { 0, 0, 0, 0 }
    43 };
     24static const char mv_longopts[] ALIGN1 =
     25    "interactive\0" No_argument "i"
     26    "force\0"       No_argument "f"
     27    ;
    4428#endif
    4529
     
    4731#define OPT_FILEUTILS_INTERACTIVE 2
    4832
    49 static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory";
     33static const char fmt[] ALIGN1 =
     34    "cannot overwrite %sdirectory with %sdirectory";
    5035
     36int mv_main(int argc, char **argv);
    5137int mv_main(int argc, char **argv)
    5238{
     
    5743    int dest_exists;
    5844    int status = 0;
     45    int copy_flag = 0;
    5946
    6047#if ENABLE_FEATURE_MV_LONG_OPTIONS
    61     bb_applet_long_options = mv_long_options;
     48    applet_long_options = mv_longopts;
    6249#endif
    63     bb_opt_complementally = "f-i:i-f";
    64     flags = bb_getopt_ulflags(argc, argv, "fi");
     50    opt_complementary = "f-i:i-f";
     51    flags = getopt32(argv, "fi");
    6552    if (optind + 2 > argc) {
    6653        bb_show_usage();
     
    7158
    7259    if (optind + 2 == argc) {
    73         if ((dest_exists = cp_mv_stat(last, &dest_stat)) < 0) {
     60        dest_exists = cp_mv_stat(last, &dest_stat);
     61        if (dest_exists < 0) {
    7462            return 1;
    7563        }
     
    8371    do {
    8472        dest = concat_path_file(last, bb_get_last_path_component(*argv));
    85 
    86         if ((dest_exists = cp_mv_stat(dest, &dest_stat)) < 0) {
     73        dest_exists = cp_mv_stat(dest, &dest_stat);
     74        if (dest_exists < 0) {
    8775            goto RET_1;
    8876        }
     
    9381            ((access(dest, W_OK) < 0 && isatty(0)) ||
    9482            (flags & OPT_FILEUTILS_INTERACTIVE))) {
    95             if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {
     83            if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
    9684                goto RET_1; /* Ouch! fprintf failed! */
    9785            }
     
    10694            if (errno != EXDEV ||
    10795                (source_exists = cp_mv_stat(*argv, &source_stat)) < 1) {
    108                 bb_perror_msg("unable to rename `%s'", *argv);
     96                bb_perror_msg("cannot rename '%s'", *argv);
    10997            } else {
    11098                if (dest_exists) {
     
    121109                    }
    122110                    if (unlink(dest) < 0) {
    123                         bb_perror_msg("cannot remove `%s'", dest);
     111                        bb_perror_msg("cannot remove '%s'", dest);
    124112                        goto RET_1;
    125113                    }
    126114                }
    127                 if ((copy_file(*argv, dest,
    128                     FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) &&
     115                copy_flag = FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS;
     116#if ENABLE_SELINUX
     117                copy_flag |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
     118#endif
     119                if ((copy_file(*argv, dest, copy_flag) >= 0) &&
    129120                    (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) {
    130121                    goto RET_0;
     
    140131    } while (*++argv != last);
    141132
    142     return (status);
     133    return status;
    143134}
Note: See TracChangeset for help on using the changeset viewer.