Skip to content

Commit

Permalink
Allow --dry-run with check command as long as --repair is not specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Oct 29, 2023
1 parent b066e98 commit 532d1ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 5 additions & 1 deletion emborg/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ def run(cls, command, args, settings, options):
verify = ["--verify-data"] if cmdline["--verify-data"] else []
repair = ['--repair'] if cmdline['--repair'] else []
if repair:
if 'dry-run' in options:
raise Error(f"--dry-run is not available with check command.")
os.environ['BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'] = 'YES'

# identify archive or archives to check
Expand Down Expand Up @@ -453,6 +455,8 @@ def run(cls, command, args, settings, options):
borg_opts = []
if cmdline["--progress"] or settings.show_progress:
borg_opts.append("--progress")
if 'dry-run' in options:
raise Error(f"--dry-run is not available with compact command.")

# run borg
borg = settings.run_borg(
Expand Down Expand Up @@ -883,7 +887,7 @@ def run(cls, command, args, settings, options):

try:
# compact the repository if requested
if settings.compact_after_delete:
if settings.compact_after_delete and not 'dry-run' in options:
narrate("Compacting repository ...")
compact = CompactCommand()
compact_status = compact.run("compact", [], settings, options)
Expand Down
11 changes: 2 additions & 9 deletions emborg/emborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@

# Globals {{{1
borg_commands_with_dryrun = "create delete extract prune upgrade recreate".split()
dangerous_borg_commands_without_dryrun = "check compact"
# The commands that modify the repository and do not support --dry-run.
# When specifying --dry-run user expects to be safe. These commands may not
# be safe. Refuse to run if user requests --dry-run on these commands.
set_shlib_prefs(use_inform=True, log_cmd=True, encoding=DEFAULT_ENCODING)

# Utilities {{{1
Expand Down Expand Up @@ -532,11 +528,8 @@ def borg_options(self, cmd, borg_opts, emborg_opts, strip_prefix):
emborg_opts.append("verbose")
if "verbose" in emborg_opts:
borg_opts.append("--verbose")
if "dry-run" in emborg_opts:
if cmd in borg_commands_with_dryrun:
borg_opts.append("--dry-run")
elif cmd in dangerous_borg_commands_without_dryrun:
raise Error(f"--dry-run is not available with {cmd} command.")
if "dry-run" in emborg_opts and cmd in borg_commands_with_dryrun:
borg_opts.append("--dry-run")

if cmd == "create":
if "verbose" in emborg_opts and "--list" not in borg_opts:
Expand Down

0 comments on commit 532d1ec

Please sign in to comment.