mirror of
https://github.com/borgbackup/borg.git
synced 2026-10-12 02:11:36 +00:00
treat empty BORG_PACK_MAX_SIZE/BORG_PACK_MAX_COUNT as unset
Matches BORG_PACK_CACHE_SIZE, where an empty value already means unset.
This commit is contained in:
@@ -987,13 +987,14 @@ class Repository:
|
||||
# pack-sizing overrides: BORG_PACK_MAX_COUNT sets the max object count per pack,
|
||||
# BORG_PACK_MAX_SIZE the max pack size in bytes. Default: size-bound only.
|
||||
# They are validated here, so a bad value fails before the store is created, opened or locked.
|
||||
# A non-integer or non-positive value is rejected. The size must also stay below
|
||||
# An empty value counts as unset, like BORG_PACK_CACHE_SIZE. A non-integer or non-positive
|
||||
# value is rejected. The size must also stay below
|
||||
# MAX_PACK_SIZE_LIMIT: add() keeps the object that crosses the cap, so this keeps packs
|
||||
# below 2 GiB, clear of OS bugs with files of 2 GiB or more. Count-only mode still passes
|
||||
# that ceiling (minus one) as max_size. pack_max_size remembers the configured size, or the
|
||||
# default when the user did not set one, so the safety ceiling does not become the compact target.
|
||||
max_count_env = os.environ.get("BORG_PACK_MAX_COUNT")
|
||||
max_size_env = os.environ.get("BORG_PACK_MAX_SIZE")
|
||||
max_count_env = os.environ.get("BORG_PACK_MAX_COUNT") or None
|
||||
max_size_env = os.environ.get("BORG_PACK_MAX_SIZE") or None
|
||||
if max_count_env is None:
|
||||
max_count = None
|
||||
else:
|
||||
|
||||
@@ -1454,7 +1454,7 @@ class FailingPackStore:
|
||||
return getattr(self._inner, name)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["0", "-1", "abc", str(MAX_PACK_SIZE_LIMIT), ""])
|
||||
@pytest.mark.parametrize("value", ["0", "-1", "abc", str(MAX_PACK_SIZE_LIMIT)])
|
||||
def test_borg_pack_max_size_rejected(tmp_path, monkeypatch, value):
|
||||
with Repository(os.fspath(tmp_path / "repo"), exclusive=True, create=True) as repository:
|
||||
pass
|
||||
@@ -1483,7 +1483,7 @@ def test_borg_pack_max_size_just_below_limit(tmp_path, monkeypatch):
|
||||
assert repository.pack_max_size == accepted
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["0", "-1", "nope", ""])
|
||||
@pytest.mark.parametrize("value", ["0", "-1", "nope"])
|
||||
def test_borg_pack_max_count_rejected(tmp_path, monkeypatch, value):
|
||||
with Repository(os.fspath(tmp_path / "repo"), exclusive=True, create=True) as repository:
|
||||
pass
|
||||
@@ -1515,6 +1515,17 @@ def test_borg_pack_limits_default_when_unset(tmp_path, monkeypatch):
|
||||
assert repository.pack_max_size == DEFAULT_PACK_MAX_SIZE
|
||||
|
||||
|
||||
def test_borg_pack_limits_empty_means_unset(tmp_path, monkeypatch):
|
||||
with Repository(os.fspath(tmp_path / "repo"), exclusive=True, create=True) as repository:
|
||||
pass
|
||||
monkeypatch.setenv("BORG_PACK_MAX_COUNT", "")
|
||||
monkeypatch.setenv("BORG_PACK_MAX_SIZE", "")
|
||||
with reopen(repository) as repository:
|
||||
assert repository._pack_writer.max_count is None
|
||||
assert repository._pack_writer.max_size == DEFAULT_PACK_MAX_SIZE
|
||||
assert repository.pack_max_size == DEFAULT_PACK_MAX_SIZE
|
||||
|
||||
|
||||
def test_borg_pack_count_and_size_both_passed_through(tmp_path, monkeypatch):
|
||||
with Repository(os.fspath(tmp_path / "repo"), exclusive=True, create=True) as repository:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user