diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile index c7409b1dc598..20aa6c0ce049 100644 --- a/usr.bin/tar/Makefile +++ b/usr.bin/tar/Makefile @@ -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} diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c index 535a8aa845d1..607e414e4c4c 100644 --- a/usr.bin/tar/bsdtar.c +++ b/usr.bin/tar/bsdtar.c @@ -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; diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h index a77ae47c9052..aada5b70b8cc 100644 --- a/usr.bin/tar/bsdtar.h +++ b/usr.bin/tar/bsdtar.h @@ -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 */ diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 0129762a8237..dc1205564be5 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -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); } /*