catch FileNotFoundError in `borg with-lock`, fixes #8022 (#8025)

borg with-lock: catch exception, print error msg, fixes #8022
This commit is contained in:
kmille 2024-01-07 00:02:43 +01:00 committed by GitHub
parent a714f77c4a
commit 3551f03af4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1850,7 +1850,10 @@ class Archiver:
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
@ -1859,6 +1862,7 @@ class Archiver:
# 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):

View File

@ -3186,6 +3186,11 @@ class ArchiverTestCase(ArchiverTestCaseBase):
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)