aboutsummaryrefslogtreecommitdiff
path: root/libbb
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 /libbb
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 'libbb')
-rw-r--r--libbb/copy_file.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4be875d2..23bcf2e82 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -64,6 +64,11 @@ static int ask_and_unlink(const char *dest, int flags)
64 bb_perror_msg("can't create '%s'", dest); 64 bb_perror_msg("can't create '%s'", dest);
65 return -1; /* error */ 65 return -1; /* error */
66 } 66 }
67#if ENABLE_FEATURE_CP_LONG_OPTIONS
68 if (flags & FILEUTILS_RMDEST)
69 if (flags & FILEUTILS_VERBOSE)
70 printf("removed '%s'\n", dest);
71#endif
67 return 1; /* ok (to try again) */ 72 return 1; /* ok (to try again) */
68} 73}
69 74
@@ -210,6 +215,22 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
210 goto preserve_mode_ugid_time; 215 goto preserve_mode_ugid_time;
211 } 216 }
212 217
218 if (dest_exists) {
219 if (flags & FILEUTILS_UPDATE) {
220 if (source_stat.st_mtime <= dest_stat.st_mtime) {
221 return 0; /* source file must be newer */
222 }
223 }
224#if ENABLE_FEATURE_CP_LONG_OPTIONS
225 if (flags & FILEUTILS_RMDEST) {
226 ovr = ask_and_unlink(dest, flags);
227 if (ovr <= 0)
228 return ovr;
229 dest_exists = 0;
230 }
231#endif
232 }
233
213 if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) { 234 if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
214 int (*lf)(const char *oldpath, const char *newpath); 235 int (*lf)(const char *oldpath, const char *newpath);
215 make_links: 236 make_links: