From owner-svn-src-all@FreeBSD.ORG Mon Jun 14 02:56:45 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4A54106566B; Mon, 14 Jun 2010 02:56:45 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BA7C98FC17; Mon, 14 Jun 2010 02:56:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o5E2ujEU022353; Mon, 14 Jun 2010 02:56:45 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o5E2ujXa022350; Mon, 14 Jun 2010 02:56:45 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <201006140256.o5E2ujXa022350@svn.freebsd.org> From: Tim Kientzle Date: Mon, 14 Jun 2010 02:56:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r209152 - head/usr.bin/tar X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2010 02:56:46 -0000 Author: kientzle Date: Mon Jun 14 02:56:45 2010 New Revision: 209152 URL: http://svn.freebsd.org/changeset/base/209152 Log: 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 Modified: head/usr.bin/tar/read.c head/usr.bin/tar/write.c Modified: head/usr.bin/tar/read.c ============================================================================== --- head/usr.bin/tar/read.c Mon Jun 14 02:31:53 2010 (r209151) +++ head/usr.bin/tar/read.c Mon Jun 14 02:56:45 2010 (r209152) @@ -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)); } Modified: head/usr.bin/tar/write.c ============================================================================== --- head/usr.bin/tar/write.c Mon Jun 14 02:31:53 2010 (r209151) +++ head/usr.bin/tar/write.c Mon Jun 14 02:56:45 2010 (r209152) @@ -965,15 +965,21 @@ report_write(struct bsdtar *bsdtar, stru 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),