aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-05-27 00:46:38 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-05-27 00:46:38 +0200
commit877dedb8251be47b3614a371434081ae9b7b358b (patch)
tree70fbac15f652ff7ce9aaada1252b4b6a0a846dad /coreutils
parent852e8dd734662d80aa82be802b066130af85b261 (diff)
downloadbusybox-w32-877dedb8251be47b3614a371434081ae9b7b358b.tar.gz
busybox-w32-877dedb8251be47b3614a371434081ae9b7b358b.tar.bz2
busybox-w32-877dedb8251be47b3614a371434081ae9b7b358b.zip
cp: add -u/--update and --remove-destination
Based on the patch by wdlkmpx@gmail.com function old new delta copy_file 1546 1644 +98 add_partition 1270 1362 +92 ask_and_unlink 95 133 +38 do_iproute 132 157 +25 decode_one_format 710 715 +5 cp_main 369 374 +5 ubirename_main 198 202 +4 read_package_field 232 230 -2 bb_make_directory 421 412 -9 packed_usage 30505 30476 -29 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/3 up/down: 267/-40) Total: 227 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cp.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 247ed0fda..2630c0d59 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -31,6 +31,7 @@
31//usage: "\n -f Overwrite" 31//usage: "\n -f Overwrite"
32//usage: "\n -i Prompt before overwrite" 32//usage: "\n -i Prompt before overwrite"
33//usage: "\n -l,-s Create (sym)links" 33//usage: "\n -l,-s Create (sym)links"
34//usage: "\n -u Copy only newer files"
34 35
35#include "libbb.h" 36#include "libbb.h"
36#include "libcoreutils/coreutils.h" 37#include "libcoreutils/coreutils.h"
@@ -49,12 +50,10 @@ int cp_main(int argc, char **argv)
49 int flags; 50 int flags;
50 int status; 51 int status;
51 enum { 52 enum {
52 OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1), 53 FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1,
53 OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
54 OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
55 OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
56#if ENABLE_FEATURE_CP_LONG_OPTIONS 54#if ENABLE_FEATURE_CP_LONG_OPTIONS
57 OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3), 55 /*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
56 OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
58#endif 57#endif
59 }; 58 };
60 59
@@ -76,10 +75,12 @@ int cp_main(int argc, char **argv)
76 "recursive\0" No_argument "R" 75 "recursive\0" No_argument "R"
77 "symbolic-link\0" No_argument "s" 76 "symbolic-link\0" No_argument "s"
78 "verbose\0" No_argument "v" 77 "verbose\0" No_argument "v"
79 "parents\0" No_argument "\xff" 78 "update\0" No_argument "u"
79 "remove-destination\0" No_argument "\xff"
80 "parents\0" No_argument "\xfe"
80 ; 81 ;
81#endif 82#endif
82 flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv"); 83 flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
83 /* Options of cp from GNU coreutils 6.10: 84 /* Options of cp from GNU coreutils 6.10:
84 * -a, --archive 85 * -a, --archive
85 * -f, --force 86 * -f, --force
@@ -94,6 +95,11 @@ int cp_main(int argc, char **argv)
94 * -d same as --no-dereference --preserve=links 95 * -d same as --no-dereference --preserve=links
95 * -p same as --preserve=mode,ownership,timestamps 96 * -p same as --preserve=mode,ownership,timestamps
96 * -c same as --preserve=context 97 * -c same as --preserve=context
98 * -u, --update
99 * copy only when the SOURCE file is newer than the destination
100 * file or when the destination file is missing
101 * --remove-destination
102 * remove each existing destination file before attempting to open
97 * --parents 103 * --parents
98 * use full source file name under DIRECTORY 104 * use full source file name under DIRECTORY
99 * NOT SUPPORTED IN BBOX: 105 * NOT SUPPORTED IN BBOX:
@@ -106,8 +112,6 @@ int cp_main(int argc, char **argv)
106 * preserve attributes (default: mode,ownership,timestamps), 112 * preserve attributes (default: mode,ownership,timestamps),
107 * if possible additional attributes: security context,links,all 113 * if possible additional attributes: security context,links,all
108 * --no-preserve=ATTR_LIST 114 * --no-preserve=ATTR_LIST
109 * --remove-destination
110 * remove each existing destination file before attempting to open
111 * --sparse=WHEN 115 * --sparse=WHEN
112 * control creation of sparse files 116 * control creation of sparse files
113 * --strip-trailing-slashes 117 * --strip-trailing-slashes
@@ -118,9 +122,6 @@ int cp_main(int argc, char **argv)
118 * copy all SOURCE arguments into DIRECTORY 122 * copy all SOURCE arguments into DIRECTORY
119 * -T, --no-target-directory 123 * -T, --no-target-directory
120 * treat DEST as a normal file 124 * treat DEST as a normal file
121 * -u, --update
122 * copy only when the SOURCE file is newer than the destination
123 * file or when the destination file is missing
124 * -x, --one-file-system 125 * -x, --one-file-system
125 * stay on this file system 126 * stay on this file system
126 * -Z, --context=CONTEXT 127 * -Z, --context=CONTEXT
@@ -156,11 +157,16 @@ int cp_main(int argc, char **argv)
156 return EXIT_FAILURE; 157 return EXIT_FAILURE;
157 158
158#if ENABLE_FEATURE_CP_LONG_OPTIONS 159#if ENABLE_FEATURE_CP_LONG_OPTIONS
160 //bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
161 // flags, FILEUTILS_RMDEST, OPT_parents);
159 if (flags & OPT_parents) { 162 if (flags & OPT_parents) {
160 if (!(d_flags & 2)) { 163 if (!(d_flags & 2)) {
161 bb_error_msg_and_die("with --parents, the destination must be a directory"); 164 bb_error_msg_and_die("with --parents, the destination must be a directory");
162 } 165 }
163 } 166 }
167 if (flags & FILEUTILS_RMDEST) {
168 flags |= FILEUTILS_FORCE;
169 }
164#endif 170#endif
165 171
166 /* ...if neither is a directory... */ 172 /* ...if neither is a directory... */