Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --list-archives-hashes #600

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
name with a null character (like `find -print0`). If one or more -v
arguments are specified, multiple null characters are used to separate
fields; see the man page for details.
- tarsnap now accepts --list-archives-hashes, which prints archive hashes.
If one or more -v arguments are specified, it will print other metadata
(as per --list-archives). This option is intended for the GUI and is not
needed for command-line usage.


Tarsnap Releases
Expand Down
6 changes: 3 additions & 3 deletions misc/bash_completion.d/tarsnap
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ _tarsnap ()
--fsck --fsck-prune --humanize-numbers --include \
--initialize-cachedir --insane-filesystems --iso-dates \
--keep-going --keep-newer-files --keyfile \
--list-archives --lowmem --maxbw --maxbw-rate \
--maxbw-rate-down --maxbw-rate-up --newer \
--newer-mtime --newer-than --newer-mtime-than \
--list-archives --list-archives-hashes --lowmem \
--maxbw --maxbw-rate --maxbw-rate-down --maxbw-rate-up \
--newer --newer-mtime --newer-than --newer-mtime-than \
--no-aggressive-networking --no-config-exclude \
--no-config-include --no-default-config \
--no-disk-pause --no-force-resources \
Expand Down
1 change: 1 addition & 0 deletions misc/describe-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
--keep-newer-files keep files which are newer than the extracted files
--keyfile specify key file
--list-archives print the names of archives stored MODE
--list-archives-hashes print the hashes of archives stored MODE
--lowmem reduce memory usage by not caching small files
--maxbw stop if more than ARG bytes of upstream bw is used
--maxbw-rate limit bandwidth to ARG bytes per second
Expand Down
49 changes: 49 additions & 0 deletions misc/zsh_completion/_tarsnap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _shtab_tarsnap_commands() {
"--fsck-prune:run as --fsck, but prune any corrupt archives"
"--initialize-cachedir:create and initialize the cachedir"
"--list-archives:print the names of archives stored"
"--list-archives-hashes:print the hashes of archives stored"
"--nuke:delete all of the archives stored"
"--print-stats:print global statistics concerning stored archives"
"--recover:recover a partial archive from a checkpoint"
Expand Down Expand Up @@ -277,6 +278,53 @@ _shtab_tarsnap__list_archives_options=(
"--version[print version number of tarsnap and exit]"
)

_shtab_tarsnap__list_archives_hashes_options=(
"(- : *)"{-h,--help}"[show this help message and exit]"
"--archive-names[read a list of archive names from a file]:filename:{_files}"
"--configfile[add file to the list of configuration files to be read]:filename:{_files}"
"--csv-file[write statistics in CSV format to a file]:filename:{_files}"
"--dump-config[print all config lines]"
"--fast-read[stop after the first entry which matches the ARG]"
"--force-resources[force the decryption of a passphrase-encrypted keyfile]"
"--humanize-numbers[use SI prefixes for --print-stats]"
"-I[read the list of names to be extracted from filename ARG]"
"--keyfile[specify key file]:key-file:{_files}"
"-l[warn unless all links to each file are archived]"
"--maxbw-rate[limit bandwidth to ARG bytes per second]:bytespersecond:"
"--maxbw-rate-down[limit download bandwidth to ARG bytes per second]:bytespersecond:"
"--maxbw-rate-up[limit upload bandwidth to ARG bytes per second]:bytespersecond:"
"--no-aggressive-networking[ignore any aggressive-networking option]"
"--no-config-exclude[ignore any exclude option]"
"--no-config-include[ignore any include option]"
"--no-default-config[do not read the default configuration files]"
"--no-disk-pause[ignore any disk-pause option]"
"--no-force-resources[ignore any force-resources option]"
"--no-humanize-numbers[ignore any humanize-numbers option]"
"--no-insane-filesystems[ignore any insane-filesystems option]"
"--no-iso-dates[ignore any iso-dates option]"
"--no-maxbw[ignore any maximum bandwidth option]"
"--no-maxbw-rate-down[ignore any download maximum bandwidth option]"
"--no-maxbw-rate-up[ignore any upload maximum bandwidth option]"
"--no-nodump[ignore any nodump option]"
"--no-print-stats[ignore any print-stats option]"
"--no-progress-bytes[ignore any progress-bytes option]"
"--no-quiet[ignore any quiet option]"
"--no-retry-forever[ignore any retry-forever option]"
"--no-snaptime[ignore any snaptime option]"
"--no-store-atime[ignore any store-atime option]"
"--no-totals[ignore any totals option]"
"--noisy-warnings[be verbose when warning about network glitches]"
"--normalmem[ignore any lowmem or verylowmem option]"
"--null[filenames or patterns are separated by null characters]"
"--passphrase[read passphrase from ARG instead of \/dev\/tty]:method\:arg:"
"--progress-bytes[print a progress messsage after each X bytes]:X:"
"--quiet[avoid printing some warnings]"
"--retry-forever[continue trying to connect to Tarsnap server forever]"
"-s[modify file or archive member names according to pattern]:pattern:"
"--verify-config[check the configuration file(s) for syntactic errors]"
"--version[print version number of tarsnap and exit]"
)

_shtab_tarsnap__nuke_options=(
"(- : *)"{-h,--help}"[show this help message and exit]"
"--archive-names[read a list of archive names from a file]:filename:{_files}"
Expand Down Expand Up @@ -842,6 +890,7 @@ _shtab_tarsnap() {
--fsck-prune) _arguments -C $_shtab_tarsnap__fsck_prune_options ;;
--initialize-cachedir) _arguments -C $_shtab_tarsnap__initialize_cachedir_options ;;
--list-archives) _arguments -C $_shtab_tarsnap__list_archives_options ;;
--list-archives-hashes) _arguments -C $_shtab_tarsnap__list_archives_hashes_options ;;
--nuke) _arguments -C $_shtab_tarsnap__nuke_options ;;
--print-stats) _arguments -C $_shtab_tarsnap__print_stats_options ;;
--recover) _arguments -C $_shtab_tarsnap__recover_options ;;
Expand Down
13 changes: 11 additions & 2 deletions tar/bsdtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ main(int argc, char **argv)
case OPTION_LIST_ARCHIVES: /* multitar */
set_mode(bsdtar, opt, "--list-archives");
break;
case OPTION_LIST_ARCHIVES_HASHES: /* tarsnap */
set_mode(bsdtar, opt, "--list-archives-hashes");
break;
case OPTION_LOWMEM: /* tarsnap */
optq_push(bsdtar, "lowmem", NULL);
break;
Expand Down Expand Up @@ -941,6 +944,7 @@ main(int argc, char **argv)
if ((bsdtar->ntapes == 0) &&
(bsdtar->mode != OPTION_PRINT_STATS &&
bsdtar->mode != OPTION_LIST_ARCHIVES &&
bsdtar->mode != OPTION_LIST_ARCHIVES_HASHES &&
bsdtar->mode != OPTION_RECOVER &&
bsdtar->mode != OPTION_FSCK &&
bsdtar->mode != OPTION_FSCK_PRUNE &&
Expand Down Expand Up @@ -1009,7 +1013,8 @@ main(int argc, char **argv)
only_mode(bsdtar, "-P", "cxt");
if (bsdtar->option_null) {
/* Allow in --list-archives or cxt modes. */
if (bsdtar->mode != OPTION_LIST_ARCHIVES)
if ((bsdtar->mode != OPTION_LIST_ARCHIVES) &&
(bsdtar->mode != OPTION_LIST_ARCHIVES_HASHES))
only_mode(bsdtar, "--null", "cxt");
}

Expand Down Expand Up @@ -1181,6 +1186,7 @@ main(int argc, char **argv)

/* FALLTHROUGH */
case OPTION_LIST_ARCHIVES:
case OPTION_LIST_ARCHIVES_HASHES:
case 'r':
case 't':
case 'x':
Expand Down Expand Up @@ -1229,7 +1235,10 @@ main(int argc, char **argv)
tarsnap_mode_recover(bsdtar, 0);
break;
case OPTION_LIST_ARCHIVES:
tarsnap_mode_list_archives(bsdtar);
tarsnap_mode_list_archives(bsdtar, 0);
break;
case OPTION_LIST_ARCHIVES_HASHES:
tarsnap_mode_list_archives(bsdtar, 1);
break;
case OPTION_NUKE:
tarsnap_mode_nuke(bsdtar);
Expand Down
3 changes: 2 additions & 1 deletion tar/bsdtar.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ enum {
OPTION_KEEP_GOING,
OPTION_KEEP_NEWER_FILES,
OPTION_LIST_ARCHIVES,
OPTION_LIST_ARCHIVES_HASHES,
OPTION_LOWMEM,
OPTION_MAXBW,
OPTION_MAXBW_RATE,
Expand Down Expand Up @@ -309,7 +310,7 @@ void tarsnap_mode_t(struct bsdtar *bsdtar);
void tarsnap_mode_x(struct bsdtar *bsdtar);
void tarsnap_mode_fsck(struct bsdtar *bsdtar, int prune, int whichkey);
void tarsnap_mode_initialize_cachedir(struct bsdtar *bsdtar);
void tarsnap_mode_list_archives(struct bsdtar *bsdtar);
void tarsnap_mode_list_archives(struct bsdtar *bsdtar, int print_hashes);
void tarsnap_mode_nuke(struct bsdtar *bsdtar);
void tarsnap_mode_recover(struct bsdtar *bsdtar, int whichkey);
int unmatched_inclusions(struct bsdtar *bsdtar);
Expand Down
1 change: 1 addition & 0 deletions tar/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static struct option {
{ "keyfile", 1, OPTION_KEYFILE },
{ "list", 0, 't' },
{ "list-archives", 0, OPTION_LIST_ARCHIVES },
{ "list-archives-hashes", 0, OPTION_LIST_ARCHIVES_HASHES },
{ "lowmem", 0, OPTION_LOWMEM },
{ "maxbw", 1, OPTION_MAXBW },
{ "maxbw-rate", 1, OPTION_MAXBW_RATE },
Expand Down
5 changes: 3 additions & 2 deletions tar/glue/tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ tarsnap_mode_print_stats(struct bsdtar *bsdtar)
* Print the names of all the archives.
*/
void
tarsnap_mode_list_archives(struct bsdtar *bsdtar)
tarsnap_mode_list_archives(struct bsdtar *bsdtar, int print_hashes)
{
TAPE_S * d;

Expand All @@ -179,7 +179,8 @@ tarsnap_mode_list_archives(struct bsdtar *bsdtar)
goto err1;

/* Ask for the list of archives to be printed. */
if (statstape_printlist(d, bsdtar->verbose, bsdtar->option_null))
if (statstape_printlist(d, bsdtar->verbose, bsdtar->option_null,
print_hashes))
goto err2;

/* We're done. Close the archive set. */
Expand Down
8 changes: 5 additions & 3 deletions tar/multitape/multitape.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ int statstape_printglobal(TAPE_S *, const char *);
int statstape_printall(TAPE_S *, const char *);

/**
* statstape_printlist(d, verbose, print_nulls):
* statstape_printlist(d, verbose, print_nulls, print_hashes):
* Print the names of each of the archives in a set. If ${verbose} > 0, print
* the creation times; if ${verbose} > 1, print the argument vector of the
* program invocation which created the archive. If ${print_nulls} > 0, print
* null character(s) between archives names and fields instead of newlines,
* tabs, and spaces.
* tabs, and spaces. If ${print_hashes} > 0 and ${verbose} is 0, print hashes
* instead of archive names. If ${print_hashes} > 0 and ${verbose} > 0, print
* hashes in addition to the normal behaviour.
*/
int statstape_printlist(TAPE_S *, int, int);
int statstape_printlist(TAPE_S *, int, int, int);

/**
* statstape_print(d, tapename, csv_filename):
Expand Down
38 changes: 31 additions & 7 deletions tar/multitape/multitape_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "chunks.h"
#include "ctassert.h"
#include "hexify.h"
#include "multitape_internal.h"
#include "storage.h"
#include "sysendian.h"
Expand Down Expand Up @@ -243,22 +244,42 @@ print_sep(char sep, int nulls, int num)
}

/**
* statstape_printlist_item(d, tapehash, verbose, print_nulls):
* statstape_printlist_item(d, tapehash, verbose, print_nulls, print_hash):
* Print the name of the archive with ${tapehash}. If ${verbose} > 0, print
* the creation times; if ${verbose} > 1, print the argument vector of the
* program invocation which created the archive. If ${print_nulls} > 0, print
* null character(s) between archives names and fields instead of newlines,
* tabs, and spaces.
* tabs, and spaces. If ${print_hash} > 0 and ${verbose} is 0, print the hash
* instead of the archive name. If ${print_hash} > 0 and ${verbose} > 0,
* print hash in addition to the normal behaviour.
*/
static int
statstape_printlist_item(TAPE_S * d, const uint8_t tapehash[32], int verbose,
int print_nulls)
int print_nulls, int print_hash)
{
struct tapemetadata tmd;
char hexstr[65];
struct tm * ltime;
char datebuf[DATEBUFLEN];
int arg;

/* Print archive hash. */
if (print_hash) {
hexify(tapehash, hexstr, 32);
fprintf(stdout, "%s", hexstr);

if (verbose == 0) {
/* We're finished; print archive separator and quit. */
if (print_sep('\n', print_nulls, 1))
goto err1;
goto done;
} else {
/* We have more fields; print field separator. */
if (print_sep('\t', print_nulls, 2))
goto err1;
}
}

/* Read the tape metadata. */
if (multitape_metadata_get_byhash(d->SR, NULL, &tmd, tapehash, 0))
goto err0;
Expand Down Expand Up @@ -317,6 +338,7 @@ statstape_printlist_item(TAPE_S * d, const uint8_t tapehash[32], int verbose,
/* Free parsed metadata. */
multitape_metadata_free(&tmd);

done:
/* Success! */
return (0);

Expand All @@ -328,15 +350,17 @@ statstape_printlist_item(TAPE_S * d, const uint8_t tapehash[32], int verbose,
}

/**
* statstape_printlist(d, verbose, print_nulls):
* statstape_printlist(d, verbose, print_nulls, print_hashes):
* Print the names of each of the archives in a set. If ${verbose} > 0, print
* the creation times; if ${verbose} > 1, print the argument vector of the
* program invocation which created the archive. If ${print_nulls} > 0, print
* null character(s) between archives names and fields instead of newlines,
* tabs, and spaces.
* tabs, and spaces. If ${print_hashes} > 0 and ${verbose} is 0, print hashes
* instead of archive names. If ${print_hashes} > 0 and ${verbose} > 0, print
* hashes in addition to the normal behaviour.
*/
int
statstape_printlist(TAPE_S * d, int verbose, int print_nulls)
statstape_printlist(TAPE_S * d, int verbose, int print_nulls, int print_hashes)
{
uint8_t * flist;
size_t nfiles;
Expand All @@ -349,7 +373,7 @@ statstape_printlist(TAPE_S * d, int verbose, int print_nulls)
/* Iterate through the files. */
for (file = 0; file < nfiles; file++) {
if (statstape_printlist_item(d, &flist[file * 32], verbose,
print_nulls))
print_nulls, print_hashes))
goto err1;
}

Expand Down
16 changes: 15 additions & 1 deletion tar/tarsnap.1-man.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
\fB\--keyfile\fP \fIkey-file\fP
.br
\fB\%tarsnap\fP
{\fB\--list-archives-hashes\fP}
\fB\--keyfile\fP \fIkey-file\fP
.br
\fB\%tarsnap\fP
{\fB\--print-stats\fP}
\fB\--keyfile\fP \fIkey-file\fP
\fB\--cachedir\fP \fIcache-dir\fP
Expand Down Expand Up @@ -124,6 +128,16 @@ If the
flag is specified two times, then the arguments in the command line will be
separated by three null characters.
.TP
\fB\--list-archives-hashes\fP
As per
\fB\--list-archive\fP,
except that it prints archive hashes.
If the
\fB\-v\fP
flag is specified one or more times, print the archive name as well.
.PP
This option is intended for the GUI and is not needed for command-line usage.
.TP
\fB\--print-stats\fP
Print global statistics concerning the archives stored, and optionally
information about individual archive(s).
Expand Down Expand Up @@ -686,7 +700,7 @@ option specified in a configuration file.
\fB\-I\fP,
\fB\-T\fP,
\fB\-X\fP,
or list-archives modes only)
list-archives, or list-archives-hashes modes only)
Filenames or patterns are separated by null characters,
not by newlines.
This is often used to read filenames output by the
Expand Down
14 changes: 13 additions & 1 deletion tar/tarsnap.1-mdoc.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
.Brq Fl -list-archives
.Fl -keyfile Ar key-file
.Nm
.Brq Fl -list-archives-hashes
.Fl -keyfile Ar key-file
.Nm
.Brq Fl -print-stats
.Fl -keyfile Ar key-file
.Fl -cachedir Ar cache-dir
Expand Down Expand Up @@ -134,6 +137,15 @@ If the
.Fl v
flag is specified two times, then the arguments in the command line will be
separated by three null characters.
.It Fl -list-archives-hashes
As per
.Fl -list-archive ,
except that it prints archive hashes.
If the
.Fl v
flag is specified one or more times, print the archive name as well.
.Pp
This option is intended for the GUI and is not needed for command-line usage.
.It Fl -print-stats
Print global statistics concerning the archives stored, and optionally
information about individual archive(s).
Expand Down Expand Up @@ -618,7 +630,7 @@ option specified in a configuration file.
.Fl I ,
.Fl T ,
.Fl X ,
or list-archives modes only)
list-archives, or list-archives-hashes modes only)
Filenames or patterns are separated by null characters,
not by newlines.
This is often used to read filenames output by the
Expand Down