summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-27 21:58:45 +0200
commit8c96ab8178ff33e9111faa0ee60dcdcb16047720 (patch)
treed1c8dc8524043095b29c72b8e075a494f51231ef /lib
parent154bc2aa3cb51104bdf213463da4fef9866c5a7b (diff)
parenta5f73a6dcd5296abb76c50615cb7c1ddfb227708 (diff)
downloadbarebox-8c96ab8178ff33e9111faa0ee60dcdcb16047720.tar.gz
barebox-8c96ab8178ff33e9111faa0ee60dcdcb16047720.tar.xz
Merge branch 'for-next/ramfs'
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index b4d87b624a..863b6833a5 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -353,10 +353,6 @@ 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 */
- if (!s && S_ISREG(dststat.st_mode))
- mode |= O_TRUNC;
-
dstfd = open(dst, mode);
if (dstfd < 0) {
printf("could not open %s: %s\n", dst, errno_str());
@@ -364,14 +360,25 @@ int copy_file(const char *src, const char *dst, int verbose)
goto out;
}
- discard_range(dstfd, srcstat.st_size, 0);
+ ret = ftruncate(dstfd, 0);
+ if (ret)
+ goto out;
+
+ 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_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);