Skip to content

Commit

Permalink
catch FileNotFoundError in borg with-lock, fixes #8022 (#8025)
Browse files Browse the repository at this point in the history
borg with-lock: catch exception, print error msg, fixes #8022
  • Loading branch information
kmille authored Jan 6, 2024
1 parent a714f77 commit 3551f03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/borg/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,10 @@ def do_with_lock(self, args, repository):
env = prepare_subprocess_env(system=True)
try:
# we exit with the return code we get from the subprocess
return subprocess.call([args.command] + args.args, env=env)
ret = subprocess.call([args.command] + args.args, env=env)
except (FileNotFoundError, OSError, ValueError) as e:
self.print_error(f"Error while trying to run '{args.command}': {e}")
ret = EXIT_ERROR
finally:
# we need to commit the "no change" operation we did to the manifest
# because it created a new segment file in the repository. if we would
Expand All @@ -1859,6 +1862,7 @@ def do_with_lock(self, args, repository):
# any other mechanism relying on existing segment data not changing).
# see issue #1867.
repository.commit(compact=False)
return ret

@with_repository(manifest=False, exclusive=True)
def do_compact(self, args, repository):
Expand Down
5 changes: 5 additions & 0 deletions src/borg/testsuite/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,11 @@ def test_with_lock(self):
cmd = 'python3', '-c', 'import os, sys; sys.exit(42 if os.path.exists("%s") else 23)' % lock_path
self.cmd('with-lock', self.repository_location, *cmd, fork=True, exit_code=42)

def test_with_lock_non_existent_command(self):
self.cmd('init', '--encryption=repokey', self.repository_location)
cmd = ['non_existent_command', ]
self.cmd('with-lock', self.repository_location, *cmd, fork=True, exit_code=EXIT_ERROR)

def test_recreate_list_output(self):
self.cmd('init', '--encryption=repokey', self.repository_location)
self.create_regular_file('file1', size=0)
Expand Down

0 comments on commit 3551f03

Please sign in to comment.