diff options
Diffstat (limited to 'libbb/copy_file.c')
-rw-r--r-- | libbb/copy_file.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index a427c441f..c52297376 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 | ||
@@ -213,6 +218,22 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags) | |||
213 | goto preserve_mode_ugid_time; | 218 | goto preserve_mode_ugid_time; |
214 | } | 219 | } |
215 | 220 | ||
221 | if (dest_exists) { | ||
222 | if (flags & FILEUTILS_UPDATE) { | ||
223 | if (source_stat.st_mtime <= dest_stat.st_mtime) { | ||
224 | return 0; /* source file must be newer */ | ||
225 | } | ||
226 | } | ||
227 | #if ENABLE_FEATURE_CP_LONG_OPTIONS | ||
228 | if (flags & FILEUTILS_RMDEST) { | ||
229 | ovr = ask_and_unlink(dest, flags); | ||
230 | if (ovr <= 0) | ||
231 | return ovr; | ||
232 | dest_exists = 0; | ||
233 | } | ||
234 | #endif | ||
235 | } | ||
236 | |||
216 | if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) { | 237 | if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) { |
217 | int (*lf)(const char *oldpath, const char *newpath); | 238 | int (*lf)(const char *oldpath, const char *newpath); |
218 | make_links: | 239 | make_links: |