Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/mv.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/mv.c
r821 r1770 4 4 * 5 5 * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu> 6 * SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp> 6 7 * 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. 21 9 */ 22 10 … … 28 16 #include <sys/types.h> 29 17 #include <sys/stat.h> 30 #include <unistd.h>31 18 #include <dirent.h> 32 #include <errno.h>33 #include <stdlib.h>34 19 #include <getopt.h> /* struct option */ 35 #include " busybox.h"20 #include "libbb.h" 36 21 #include "libcoreutils/coreutils.h" 37 22 38 23 #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 }; 24 static const char mv_longopts[] ALIGN1 = 25 "interactive\0" No_argument "i" 26 "force\0" No_argument "f" 27 ; 44 28 #endif 45 29 … … 47 31 #define OPT_FILEUTILS_INTERACTIVE 2 48 32 49 static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory"; 33 static const char fmt[] ALIGN1 = 34 "cannot overwrite %sdirectory with %sdirectory"; 50 35 36 int mv_main(int argc, char **argv); 51 37 int mv_main(int argc, char **argv) 52 38 { … … 57 43 int dest_exists; 58 44 int status = 0; 45 int copy_flag = 0; 59 46 60 47 #if ENABLE_FEATURE_MV_LONG_OPTIONS 61 bb_applet_long_options = mv_long_options;48 applet_long_options = mv_longopts; 62 49 #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"); 65 52 if (optind + 2 > argc) { 66 53 bb_show_usage(); … … 71 58 72 59 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) { 74 62 return 1; 75 63 } … … 83 71 do { 84 72 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) { 87 75 goto RET_1; 88 76 } … … 93 81 ((access(dest, W_OK) < 0 && isatty(0)) || 94 82 (flags & OPT_FILEUTILS_INTERACTIVE))) { 95 if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {83 if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) { 96 84 goto RET_1; /* Ouch! fprintf failed! */ 97 85 } … … 106 94 if (errno != EXDEV || 107 95 (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); 109 97 } else { 110 98 if (dest_exists) { … … 121 109 } 122 110 if (unlink(dest) < 0) { 123 bb_perror_msg("cannot remove `%s'", dest);111 bb_perror_msg("cannot remove '%s'", dest); 124 112 goto RET_1; 125 113 } 126 114 } 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) && 129 120 (remove_file(*argv, FILEUTILS_RECUR | FILEUTILS_FORCE) >= 0)) { 130 121 goto RET_0; … … 140 131 } while (*++argv != last); 141 132 142 return (status);133 return status; 143 134 }
Note:
See TracChangeset
for help on using the changeset viewer.