summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-08-07 19:25:34 +0000
committerkientzle <kientzle@FreeBSD.org>2004-08-07 19:25:34 +0000
commit0457e08c653c231b3bd5e744be22bb94567aff37 (patch)
tree57f2b04ee1ff6080ae7e3bd0fa8821ba50b4d411 /usr.bin/tar
parentce43965b8b0a3777d17e84b790b1da388f3da574 (diff)
downloadFreeBSD-src-0457e08c653c231b3bd5e744be22bb94567aff37.zip
FreeBSD-src-0457e08c653c231b3bd5e744be22bb94567aff37.tar.gz
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.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/Makefile2
-rw-r--r--usr.bin/tar/bsdtar.c9
-rw-r--r--usr.bin/tar/bsdtar.h1
-rw-r--r--usr.bin/tar/write.c16
4 files changed, 25 insertions, 3 deletions
diff --git a/usr.bin/tar/Makefile b/usr.bin/tar/Makefile
index c7409b1..20aa6c0 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 535a8aa..607e414 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 a77ae47c..aada5b7 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 0129762..dc12055 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);
}
/*
OpenPOWER on IntegriCloud