Add --totals option. Unlike gtar, this reports the bytes actually

written to the archive, not the ones written to the compressor.
For uncompressed archives, these numbers are the same, of course.
This commit is contained in:
Tim Kientzle 2004-08-07 19:25:34 +00:00
parent 91ce8f27d8
commit 8095e9d82b
4 changed files with 25 additions and 3 deletions

View File

@ -6,7 +6,7 @@
#
PROG= bsdtar
VERSION= 1.00
VERSION= 1.01
SRCS= bsdtar.c matching.c read.c util.c write.c
WARNS?= 6
DPADD= ${LIBARCHIVE} ${LIBBZ2} ${LIBZ}

View File

@ -66,11 +66,11 @@ struct option {
#include "bsdtar.h"
#ifdef linux
#define _PATH_DEFTAPE "/dev/st0"
#define _PATH_DEFTAPE "/dev/st0"
#endif
#ifndef _PATH_DEFTAPE
#define _PATH_DEFTAPE "/dev/tape"
#define _PATH_DEFTAPE "/dev/tape"
#endif
static int bsdtar_getopt(struct bsdtar *, const char *optstring,
@ -115,6 +115,7 @@ static const char *tar_opts = "+Bb:C:cF:f:HhjkLlmnOoPprtT:UuvW:wX:xyZz";
#define OPTION_NO_SAME_PERMISSIONS 21
#define OPTION_NULL 24
#define OPTION_ONE_FILE_SYSTEM 27
#define OPTION_TOTALS 28
#define OPTION_VERSION 30
static const struct option tar_longopts[] = {
@ -155,6 +156,7 @@ static const struct option tar_longopts[] = {
{ "read-full-blocks", no_argument, NULL, 'B' },
{ "same-permissions", no_argument, NULL, 'p' },
{ "to-stdout", no_argument, NULL, 'O' },
{ "totals", no_argument, NULL, OPTION_TOTALS },
{ "unlink", no_argument, NULL, 'U' },
{ "unlink-first", no_argument, NULL, 'U' },
{ "update", no_argument, NULL, 'u' },
@ -380,6 +382,9 @@ main(int argc, char **argv)
mode = opt;
bsdtar->verbose++;
break;
case OPTION_TOTALS: /* GNU tar */
bsdtar->option_totals++;
break;
case 'U': /* GNU tar */
bsdtar->extract_flags |= ARCHIVE_EXTRACT_UNLINK;
bsdtar->option_unlink_first = 1;

View File

@ -62,6 +62,7 @@ struct bsdtar {
char option_no_subdirs; /* -d */
char option_null; /* --null */
char option_stdout; /* -p */
char option_totals; /* --totals */
char option_unlink_first; /* -U */
char option_warn_links; /* -l */
char day_first; /* show day before month in -tv output */

View File

@ -192,6 +192,11 @@ tar_mode_c(struct bsdtar *bsdtar)
write_archive(a, bsdtar);
if (bsdtar->option_totals) {
fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
(BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
}
archive_write_finish(a);
}
@ -252,6 +257,11 @@ tar_mode_r(struct bsdtar *bsdtar)
write_archive(a, bsdtar); /* XXX check return val XXX */
if (bsdtar->option_totals) {
fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
(BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
}
archive_write_finish(a);
close(bsdtar->fd);
bsdtar->fd = -1;
@ -331,6 +341,11 @@ tar_mode_u(struct bsdtar *bsdtar)
write_archive(a, bsdtar);
if (bsdtar->option_totals) {
fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n",
(BSDTAR_FILESIZE_TYPE)archive_position_compressed(a));
}
archive_write_finish(a);
close(bsdtar->fd);
bsdtar->fd = -1;
@ -459,6 +474,7 @@ write_archive(struct archive *a, struct bsdtar *bsdtar)
}
create_cleanup(bsdtar);
archive_write_close(a);
}
/*