make BORG_EXIT_CODES="modern" the default.

This commit is contained in:
Thomas Waldmann 2024-07-19 17:31:36 +02:00
parent 3c480d9057
commit ecddbc6691
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
6 changed files with 20 additions and 9 deletions

View File

@ -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

View File

@ -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):

View File

@ -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!

View File

@ -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()

View File

@ -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)

View File

@ -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