diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 0f0867dd5..357defa74 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -36,7 +36,7 @@ from .cache import Cache from .constants import * # NOQA from .crc32 import crc32 from .helpers import EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR -from .helpers import Error, NoManifestError +from .helpers import Error, NoManifestError, set_ec from .helpers import location_validator, archivename_validator, ChunkerParams, CompressionSpec from .helpers import PrefixSpec, SortBySpec, HUMAN_SORT_KEYS from .helpers import BaseFormatter, ItemFormatter, ArchiveFormatter @@ -3372,7 +3372,7 @@ class Archiver: self.prerun_checks(logger) if is_slow_msgpack(): logger.warning("Using a pure-python msgpack! This will result in lower performance.") - return func(args) + return set_ec(func(args)) def sig_info_handler(sig_no, stack): # pragma: no cover diff --git a/src/borg/helpers.py b/src/borg/helpers.py index 37adad23a..fe82b92f7 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -52,6 +52,26 @@ def Chunk(data, **meta): return _Chunk(meta, data) +''' +The global exit_code variable is used so that modules other than archiver can increase the program exit code if a +warning or error occured during their operation. This is different from archiver.exit_code, which is only accessible +from the archiver object. +''' +exit_code = EXIT_SUCCESS + + +def set_ec(ec): + ''' + Sets the exit code of the program, if an exit code higher or equal than this is set, this does nothing. This + makes EXIT_ERROR override EXIT_WARNING, etc.. + + ec: exit code to set + ''' + global exit_code + exit_code = max(exit_code, ec) + return exit_code + + class Error(Exception): """Error base class""" diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index a8f4d95a5..e2184a67c 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -79,6 +79,7 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw): archiver = Archiver() archiver.prerun_checks = lambda *args: None archiver.exit_code = EXIT_SUCCESS + helpers.exit_code = EXIT_SUCCESS try: args = archiver.parse_args(list(args)) # argparse parsing may raise SystemExit when the command line is bad or