diff options
Diffstat (limited to 'lib/libfile.c')
-rw-r--r-- | lib/libfile.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/libfile.c b/lib/libfile.c index b4d87b624a..20bb689a79 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -353,7 +353,7 @@ int copy_file(const char *src, const char *dst, int verbose) goto out; } - /* Set O_TRUNC only if file exist and is a regular file */ + /* Set O_TRUNC only if file exists and is a regular file */ if (!s && S_ISREG(dststat.st_mode)) mode |= O_TRUNC; @@ -364,14 +364,21 @@ int copy_file(const char *src, const char *dst, int verbose) goto out; } - discard_range(dstfd, srcstat.st_size, 0); + ret = stat(src, &srcstat); + if (ret) + goto out; - if (verbose) { - if (stat(src, &srcstat) < 0) - srcstat.st_size = 0; + if (srcstat.st_size != FILESIZE_MAX) { + discard_range(dstfd, srcstat.st_size, 0); + if (s || S_ISREG(dststat.st_mode)) { + ret = ftruncate(dstfd, srcstat.st_size); + if (ret) + goto out; + } + } + if (verbose) init_progression_bar(srcstat.st_size); - } while (1) { r = read(srcfd, rw_buf, RW_BUF_SIZE); |