From ecddbc6691b1dc6988c61f3b62c50f134f790ce4 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 19 Jul 2024 17:31:36 +0200 Subject: [PATCH] make BORG_EXIT_CODES="modern" the default. --- docs/usage/general/environment.rst.inc | 3 ++- src/borg/helpers/errors.py | 2 +- src/borg/testsuite/archiver/create_cmd.py | 7 +++++-- src/borg/testsuite/archiver/extract_cmd.py | 7 +++++-- src/borg/testsuite/archiver/lock_cmds.py | 4 +++- src/borg/testsuite/archiver/return_codes.py | 6 ++++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/usage/general/environment.rst.inc b/docs/usage/general/environment.rst.inc index b386dc465..cd89f8d50 100644 --- a/docs/usage/general/environment.rst.inc +++ b/docs/usage/general/environment.rst.inc @@ -38,7 +38,8 @@ General: When set, use the value to answer the "display the passphrase for verification" question when defining a new passphrase for encrypted repositories. BORG_EXIT_CODES When set to "modern", the borg process will return more specific exit codes (rc). - Default is "legacy" and returns rc 2 for all errors, 1 for all warnings, 0 for success. + When set to "legacy", the borg process will return rc 2 for all errors, 1 for all warnings, 0 for success. + Default is "modern". BORG_HOST_ID Borg usually computes a host id from the FQDN plus the results of ``uuid.getnode()`` (which usually returns a unique id based on the MAC address of the network interface. Except if that MAC happens to be all-zero - in diff --git a/src/borg/helpers/errors.py b/src/borg/helpers/errors.py index d19048a6a..1091bddf7 100644 --- a/src/borg/helpers/errors.py +++ b/src/borg/helpers/errors.py @@ -5,7 +5,7 @@ from ..constants import * # NOQA from ..crypto.low_level import IntegrityError as IntegrityErrorBase -modern_ec = os.environ.get("BORG_EXIT_CODES", "legacy") == "modern" +modern_ec = os.environ.get("BORG_EXIT_CODES", "modern") == "modern" # "legacy" was used by borg < 2 class ErrorBase(Exception): diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index 4d7626d2b..4bea39f90 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -17,7 +17,7 @@ from ...constants import * # NOQA from ...manifest import Manifest from ...platform import is_cygwin, is_win32, is_darwin from ...repository import Repository -from ...helpers import CommandError +from ...helpers import CommandError, BackupPermissionError from .. import has_lchflags from .. import changedir from .. import ( @@ -304,6 +304,9 @@ def test_create_no_permission_file(archivers, request): os.chmod(file_path + "2", 0o000) cmd(archiver, "rcreate", RK_ENCRYPTION) flist = "".join(f"input/file{n}\n" for n in range(1, 4)) + expected_ec = BackupPermissionError("open", OSError(13, "permission denied")).exit_code + if expected_ec == EXIT_ERROR: # workaround, TODO: fix it + expected_ec = EXIT_WARNING out = cmd( archiver, "create", @@ -311,7 +314,7 @@ def test_create_no_permission_file(archivers, request): "--list", "test", input=flist.encode(), - exit_code=1, # WARNING status: could not back up file2. + exit_code=expected_ec, # WARNING status: could not back up file2. ) assert "retry: 1 of " not in out # retries were NOT attempted! assert "E input/file2" in out # no permissions! diff --git a/src/borg/testsuite/archiver/extract_cmd.py b/src/borg/testsuite/archiver/extract_cmd.py index 46d4d26db..b289cee70 100644 --- a/src/borg/testsuite/archiver/extract_cmd.py +++ b/src/borg/testsuite/archiver/extract_cmd.py @@ -9,7 +9,7 @@ import pytest from ... import xattr from ...chunker import has_seek_hole from ...constants import * # NOQA -from ...helpers import EXIT_WARNING +from ...helpers import EXIT_WARNING, BackupOSError from ...helpers import flags_noatime, flags_normal from .. import changedir, same_ts_ns from .. import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported, is_birthtime_fully_supported @@ -621,8 +621,11 @@ def test_overwrite(archivers, request): os.unlink("output/input/file1") os.mkdir("output/input/file1") os.mkdir("output/input/file1/dir") + expected_ec = BackupOSError("open", OSError(21, "is a directory")).exit_code # WARNING code + if expected_ec == EXIT_ERROR: # workaround, TODO: fix it + expected_ec = EXIT_WARNING with changedir("output"): - cmd(archiver, "extract", "test", exit_code=1) + cmd(archiver, "extract", "test", exit_code=expected_ec) # derived from test_extract_xattrs_errors() diff --git a/src/borg/testsuite/archiver/lock_cmds.py b/src/borg/testsuite/archiver/lock_cmds.py index 32479c1ba..20cfbd7da 100644 --- a/src/borg/testsuite/archiver/lock_cmds.py +++ b/src/borg/testsuite/archiver/lock_cmds.py @@ -2,6 +2,7 @@ import os from ...constants import * # NOQA from . import cmd, generate_archiver_tests, RK_ENCRYPTION +from ...helpers import CommandError pytest_generate_tests = lambda metafunc: generate_archiver_tests(metafunc, kinds="local,remote,binary") # NOQA @@ -24,4 +25,5 @@ def test_with_lock_non_existent_command(archivers, request): archiver = request.getfixturevalue(archivers) cmd(archiver, "rcreate", RK_ENCRYPTION) command = ["non_existent_command"] - cmd(archiver, "with-lock", *command, fork=True, exit_code=EXIT_ERROR) + expected_ec = CommandError().exit_code + cmd(archiver, "with-lock", *command, fork=True, exit_code=expected_ec) diff --git a/src/borg/testsuite/archiver/return_codes.py b/src/borg/testsuite/archiver/return_codes.py index 05fa22200..9c23f7995 100644 --- a/src/borg/testsuite/archiver/return_codes.py +++ b/src/borg/testsuite/archiver/return_codes.py @@ -1,4 +1,6 @@ +from ...archive import Archive from ...constants import * # NOQA +from ...helpers import IncludePatternNeverMatchedWarning from . import cmd_fixture, changedir # NOQA @@ -15,6 +17,6 @@ def test_return_codes(cmd_fixture, tmpdir): rc, out = cmd_fixture("--repo=%s" % repo, "extract", "archive") assert rc == EXIT_SUCCESS rc, out = cmd_fixture("--repo=%s" % repo, "extract", "archive", "does/not/match") - assert rc == EXIT_WARNING # pattern did not match + assert rc == IncludePatternNeverMatchedWarning().exit_code rc, out = cmd_fixture("--repo=%s" % repo, "create", "archive", str(input)) - assert rc == EXIT_ERROR # duplicate archive name + assert rc == Archive.AlreadyExists().exit_code