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>
This commit is contained in:
@@ -64,6 +64,11 @@ static int ask_and_unlink(const char *dest, int flags)
|
||||
bb_perror_msg("can't create '%s'", dest);
|
||||
return -1; /* error */
|
||||
}
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & FILEUTILS_RMDEST)
|
||||
if (flags & FILEUTILS_VERBOSE)
|
||||
printf("removed '%s'\n", dest);
|
||||
#endif
|
||||
return 1; /* ok (to try again) */
|
||||
}
|
||||
|
||||
@@ -210,6 +215,22 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
|
||||
goto preserve_mode_ugid_time;
|
||||
}
|
||||
|
||||
if (dest_exists) {
|
||||
if (flags & FILEUTILS_UPDATE) {
|
||||
if (source_stat.st_mtime <= dest_stat.st_mtime) {
|
||||
return 0; /* source file must be newer */
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & FILEUTILS_RMDEST) {
|
||||
ovr = ask_and_unlink(dest, flags);
|
||||
if (ovr <= 0)
|
||||
return ovr;
|
||||
dest_exists = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
|
||||
int (*lf)(const char *oldpath, const char *newpath);
|
||||
make_links:
|
||||
|
Reference in New Issue
Block a user