Skip to content

Commit

Permalink
Add --dry-run-metadata boilerplate (no functionality)
Browse files Browse the repository at this point in the history
The only interesting facets of this commit are:

- internally, we store this as bsdtar->option_dryrun == 2; the existing
  --dry-run option is stored as 1.

- we disallow the combination of --dry-run-metadata with --print-stats,
  because the --print-stats (generated from the chunk layer) would only
  report metadata and metaindex bytes (since no filesystem data will
  reach the chunk layer).
  • Loading branch information
gperciva committed Dec 26, 2023
1 parent 21d8ed7 commit 614335d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tar/bsdtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,17 @@ main(int argc, char **argv)
optq_push(bsdtar, "disk-pause", bsdtar->optarg);
break;
case OPTION_DRYRUN: /* tarsnap */
if (bsdtar->option_dryrun != 0)
bsdtar_errc(bsdtar, 1, 0,
"Can only specify one --dry-run* option");
bsdtar->option_dryrun = 1;
break;
case OPTION_DRYRUN_METADATA: /* tarsnap */
if (bsdtar->option_dryrun != 0)
bsdtar_errc(bsdtar, 1, 0,
"Can only specify one --dry-run* option");
bsdtar->option_dryrun = 2;
break;
case OPTION_EXCLUDE: /* GNU tar */
optq_push(bsdtar, "exclude", bsdtar->optarg);
break;
Expand Down Expand Up @@ -988,6 +997,9 @@ main(int argc, char **argv)
tarsnap_opt_aggressive_networking = 0;
}
}
if ((bsdtar->option_dryrun == 2) && bsdtar->option_print_stats)
bsdtar_errc(bsdtar, 1, 0, "--dry-run-metadata is "
"incompatible with --print-stats");

/*
* The -f option doesn't make sense for --fsck, --fsck-prune, or
Expand Down Expand Up @@ -1044,8 +1056,10 @@ main(int argc, char **argv)
only_mode(bsdtar, "-U", "x");
if (bsdtar->option_warn_links)
only_mode(bsdtar, "--check-links", "c");
if (bsdtar->option_dryrun)
if (bsdtar->option_dryrun == 1)
only_mode(bsdtar, "--dry-run", "c");
if (bsdtar->option_dryrun == 2)
only_mode(bsdtar, "--dry-run-metadata", "c");

/* Check other parameters only permitted in certain modes. */
if (bsdtar->symlink_mode != '\0') {
Expand Down
3 changes: 2 additions & 1 deletion tar/bsdtar.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct bsdtar {
char option_chroot; /* --chroot */
char *option_csv_filename; /* --csv-filename */
char option_dont_traverse_mounts; /* --one-file-system */
char option_dryrun; /* --dry-run */
char option_dryrun; /* --dry-run / --dry-run-metadata */
char option_fast_read; /* --fast-read */
int option_hashes;
char option_honor_nodump; /* --nodump */
Expand Down Expand Up @@ -207,6 +207,7 @@ enum {
OPTION_DEBUG_NETWORK_STATS,
OPTION_DISK_PAUSE,
OPTION_DRYRUN,
OPTION_DRYRUN_METADATA,
OPTION_DUMP_CONFIG,
OPTION_EXCLUDE,
OPTION_FORCE_RESOURCES,
Expand Down
1 change: 1 addition & 0 deletions tar/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static struct option {
{ "directory", 1, 'C' },
{ "disk-pause", 1, OPTION_DISK_PAUSE },
{ "dry-run", 0, OPTION_DRYRUN },
{ "dry-run-metadata", 0, OPTION_DRYRUN_METADATA },
{ "dump-config", 0, OPTION_DUMP_CONFIG },
{ "exclude", 1, OPTION_EXCLUDE },
{ "exclude-from", 1, 'X' },
Expand Down

0 comments on commit 614335d

Please sign in to comment.