diff --git a/src/btrfs2s3/_internal/commands/update.py b/src/btrfs2s3/_internal/commands/update.py index 6538f9a..58be845 100644 --- a/src/btrfs2s3/_internal/commands/update.py +++ b/src/btrfs2s3/_internal/commands/update.py @@ -378,16 +378,6 @@ def command(*, console: Console, args: argparse.Namespace) -> int: s3_endpoint = s3_remote.get("endpoint", {}) sources = config["sources"] - assert ( # noqa: S101 - len( - { - upload["preserve"] - for source in sources - for upload in source["upload_to_remotes"] - } - ) - == 1 - ) assert ( # noqa: S101 len( { diff --git a/src/btrfs2s3/_internal/config.py b/src/btrfs2s3/_internal/config.py index 69270d0..64b5e54 100644 --- a/src/btrfs2s3/_internal/config.py +++ b/src/btrfs2s3/_internal/config.py @@ -198,9 +198,17 @@ def load_from_path(path: str | PathLike[str]) -> Config: msg = "multiple remotes not supported in this release" raise InvalidConfigError(msg) + all_sources = config["sources"] + # https://github.com/sbrudenell/btrfs2s3/issues/81 - if len({source["snapshots"] for source in config["sources"]}) > 1: + if len({source["snapshots"] for source in all_sources}) > 1: msg = "multiple snapshot locations not supported in this release" raise InvalidConfigError(msg) + all_uploads = [up for src in all_sources for up in src["upload_to_remotes"]] + + if len({upload["preserve"] for upload in all_uploads}) > 1: + msg = "multiple preserve configurations not supported in this release" + raise InvalidConfigError(msg) + return config diff --git a/tests/config_test.py b/tests/config_test.py index 6de45b6..4151103 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -267,3 +267,26 @@ def test_no_multiple_snapshot_locations(path: Path) -> None: """) with pytest.raises(InvalidConfigError): load_from_path(path) + + +def test_no_multiple_preserves(path: Path) -> None: + path.write_text(""" + timezone: a + sources: + - path: b + snapshots: c + upload_to_remotes: + - id: aws + preserve: 1y 1m + - path: x + snapshots: c + upload_to_remotes: + - id: aws + preserve: 1y + remotes: + - id: aws + s3: + bucket: d + """) + with pytest.raises(InvalidConfigError): + load_from_path(path)