summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2010-06-14 02:56:45 +0000
committerkientzle <kientzle@FreeBSD.org>2010-06-14 02:56:45 +0000
commit3554fa67c2e9a3bb8ef3527a578d37fac08f4027 (patch)
tree08da7b35efab8db241147ce1619b030aba452d0d /usr.bin
parentd044db72cde3de09555ea28bbefb87928e06cba2 (diff)
downloadFreeBSD-src-3554fa67c2e9a3bb8ef3527a578d37fac08f4027.zip
FreeBSD-src-3554fa67c2e9a3bb8ef3527a578d37fac08f4027.tar.gz
If the compressed data is larger than the uncompressed,
report the compression ratio as 0% instead of displaying nonsense triggered by numeric overflow. This is common when dealing with uncompressed files when the I/O blocking causes there to be small transient differences in the accounting. Thanks to: Boris Samorodov
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tar/read.c7
-rw-r--r--usr.bin/tar/write.c8
2 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index c0e5bcb..525daac 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -103,6 +103,7 @@ progress_func(void *cookie)
struct archive *a = progress_data->archive;
struct archive_entry *entry = progress_data->entry;
uint64_t comp, uncomp;
+ int compression;
if (!need_report())
return;
@@ -112,9 +113,13 @@ progress_func(void *cookie)
if (a != NULL) {
comp = archive_position_compressed(a);
uncomp = archive_position_uncompressed(a);
+ if (comp > uncomp)
+ compression = 0;
+ else
+ compression = (int)((uncomp - comp) * 100 / uncomp);
fprintf(stderr,
"In: %s bytes, compression %d%%;",
- tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
+ tar_i64toa(comp), compression);
fprintf(stderr, " Out: %d files, %s bytes\n",
archive_file_count(a), tar_i64toa(uncomp));
}
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c
index 207122e..e59f647 100644
--- a/usr.bin/tar/write.c
+++ b/usr.bin/tar/write.c
@@ -965,15 +965,21 @@ report_write(struct bsdtar *bsdtar, struct archive *a,
struct archive_entry *entry, int64_t progress)
{
uint64_t comp, uncomp;
+ int compression;
+
if (bsdtar->verbose)
fprintf(stderr, "\n");
comp = archive_position_compressed(a);
uncomp = archive_position_uncompressed(a);
fprintf(stderr, "In: %d files, %s bytes;",
archive_file_count(a), tar_i64toa(uncomp));
+ if (comp > uncomp)
+ compression = 0;
+ else
+ compression = (int)((uncomp - comp) * 100 / uncomp);
fprintf(stderr,
" Out: %s bytes, compression %d%%\n",
- tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
+ tar_i64toa(comp), compression);
/* Can't have two calls to tar_i64toa() pending, so split the output. */
safe_fprintf(stderr, "Current: %s (%s",
archive_entry_pathname(entry),
OpenPOWER on IntegriCloud