diff options
author | Hubert Feurstein <h.feurstein@gmail.com> | 2011-11-22 11:24:44 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-11-22 21:13:05 +0100 |
commit | 7bb009c74480153b02a2e0d976a136bf7716e2ab (patch) | |
tree | b35c8f55c7edf3536be73428a4ef69cd57a30305 /lib | |
parent | a59471d133e0f80e7e1095b0cb161e31341694ad (diff) | |
download | barebox-7bb009c74480153b02a2e0d976a136bf7716e2ab.tar.gz barebox-7bb009c74480153b02a2e0d976a136bf7716e2ab.tar.xz |
commands/cp: add verbose mode which displays progress bar
Signed-off-by: Hubert Feurstein <h.feurstein@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/copy_file.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/copy_file.c b/lib/copy_file.c index 809befe369..967806c3b0 100644 --- a/lib/copy_file.c +++ b/lib/copy_file.c @@ -4,20 +4,23 @@ #include <errno.h> #include <malloc.h> #include <libbb.h> +#include <progress.h> #define RW_BUF_SIZE (ulong)4096 /** * @param[in] src FIXME * @param[out] dst FIXME + * @param[in] verbose FIXME */ -int copy_file(const char *src, const char *dst) +int copy_file(const char *src, const char *dst, int verbose) { char *rw_buf = NULL; int srcfd = 0, dstfd = 0; int r, w; int ret = 1; void *buf; + int total = 0; rw_buf = xmalloc(RW_BUF_SIZE); @@ -33,6 +36,15 @@ int copy_file(const char *src, const char *dst) goto out; } + if (verbose) { + struct stat statbuf; + + if (stat(src, &statbuf) < 0) + statbuf.st_size = 0; + + init_progression_bar(statbuf.st_size); + } + while(1) { r = read(srcfd, rw_buf, RW_BUF_SIZE); if (r < 0) { @@ -51,11 +63,18 @@ int copy_file(const char *src, const char *dst) } buf += w; r -= w; + total += w; } + + if (verbose) + show_progress(total); } ret = 0; out: + if (verbose) + putchar('\n'); + free(rw_buf); if (srcfd > 0) close(srcfd); |