mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-10 09:21:44 -04:00
rename v1_or_v2 to v1_legacy
The v2 repo format was only used by early borg2 alphas/betas, before borgstore was introduced. For borg transfer, we only need to support reading v1 repos of borg 1.x.
This commit is contained in:
parent
e46a06add8
commit
828e72be72
6 changed files with 26 additions and 26 deletions
|
|
@ -29,9 +29,9 @@ from ..logger import create_logger
|
|||
logger = create_logger(__name__)
|
||||
|
||||
|
||||
def get_repository(location, *, create, exclusive, lock_wait, lock, args, v1_or_v2):
|
||||
def get_repository(location, *, create, exclusive, lock_wait, lock, args, v1_legacy):
|
||||
if location.proto in ("ssh", "socket"):
|
||||
if v1_or_v2:
|
||||
if v1_legacy:
|
||||
from ..legacy.remote import LegacyRemoteRepository
|
||||
|
||||
RemoteRepoCls = LegacyRemoteRepository
|
||||
|
|
@ -42,12 +42,12 @@ def get_repository(location, *, create, exclusive, lock_wait, lock, args, v1_or_
|
|||
)
|
||||
|
||||
elif (
|
||||
location.proto in ("sftp", "file", "http", "https", "rclone", "s3", "b2") and not v1_or_v2
|
||||
location.proto in ("sftp", "file", "http", "https", "rclone", "s3", "b2") and not v1_legacy
|
||||
): # stuff directly supported by borgstore
|
||||
repository = Repository(location, create=create, exclusive=exclusive, lock_wait=lock_wait, lock=lock)
|
||||
|
||||
else:
|
||||
if v1_or_v2:
|
||||
if v1_legacy:
|
||||
from ..legacy.repository import LegacyRepository
|
||||
|
||||
RepoCls = LegacyRepository
|
||||
|
|
@ -123,7 +123,7 @@ def with_repository(
|
|||
lock_wait=self.lock_wait,
|
||||
lock=lock,
|
||||
args=args,
|
||||
v1_or_v2=False,
|
||||
v1_legacy=False,
|
||||
)
|
||||
|
||||
with repository:
|
||||
|
|
@ -181,7 +181,7 @@ def with_other_repository(manifest=False, cache=False, compatibility=None):
|
|||
if not location.valid: # nothing to do
|
||||
return method(self, args, **kwargs)
|
||||
|
||||
v1_or_v2 = getattr(args, "v1_or_v2", False)
|
||||
v1_legacy = getattr(args, "v1_legacy", False)
|
||||
|
||||
repository = get_repository(
|
||||
location,
|
||||
|
|
@ -190,11 +190,11 @@ def with_other_repository(manifest=False, cache=False, compatibility=None):
|
|||
lock_wait=self.lock_wait,
|
||||
lock=True,
|
||||
args=args,
|
||||
v1_or_v2=v1_or_v2,
|
||||
v1_legacy=v1_legacy,
|
||||
)
|
||||
|
||||
with repository:
|
||||
acceptable_versions = (1, 2) if v1_or_v2 else (3,)
|
||||
acceptable_versions = (1,) if v1_legacy else (3,)
|
||||
if repository.version not in acceptable_versions:
|
||||
raise Error(
|
||||
f"This borg version only accepts version {' or '.join(acceptable_versions)} "
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class RepoCreateMixIn:
|
|||
help="reuse the key material from the other repository",
|
||||
)
|
||||
subparser.add_argument(
|
||||
"--from-borg1", dest="v1_or_v2", action="store_true", help="other repository is Borg 1.x"
|
||||
"--from-borg1", dest="v1_legacy", action="store_true", help="other repository is Borg 1.x"
|
||||
)
|
||||
subparser.add_argument(
|
||||
"-e",
|
||||
|
|
|
|||
|
|
@ -175,9 +175,9 @@ class TransferMixIn:
|
|||
from .. import upgrade as upgrade_mod
|
||||
from ..legacy import upgrade as legacy_upgrade_mod
|
||||
|
||||
v1_or_v2 = getattr(args, "v1_or_v2", False)
|
||||
v1_legacy = getattr(args, "v1_legacy", False)
|
||||
upgrader = args.upgrader
|
||||
if upgrader == "NoOp" and v1_or_v2:
|
||||
if upgrader == "NoOp" and v1_legacy:
|
||||
upgrader = "From12To20"
|
||||
|
||||
try:
|
||||
|
|
@ -350,7 +350,7 @@ class TransferMixIn:
|
|||
help="transfer archives from the other repository",
|
||||
)
|
||||
subparser.add_argument(
|
||||
"--from-borg1", dest="v1_or_v2", action="store_true", help="other repository is borg 1.x"
|
||||
"--from-borg1", dest="v1_legacy", action="store_true", help="other repository is borg 1.x"
|
||||
)
|
||||
subparser.add_argument(
|
||||
"--upgrader",
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ class LegacyRemoteRepository:
|
|||
lock_wait=lock_wait,
|
||||
lock=lock,
|
||||
exclusive=exclusive,
|
||||
v1_or_v2=True, # make remote use LegacyRepository
|
||||
v1_legacy=True, # make remote use LegacyRepository
|
||||
)
|
||||
info = self.info()
|
||||
self.version = info["version"]
|
||||
|
|
@ -636,8 +636,8 @@ class LegacyRemoteRepository:
|
|||
if chunkid in self.chunkid_to_msgids:
|
||||
self.ignore_responses.add(pop_preload_msgid(chunkid))
|
||||
|
||||
@api(since=parse_version("1.0.0"), v1_or_v2={"since": parse_version("2.0.0b10"), "previously": True})
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, v1_or_v2=False):
|
||||
@api(since=parse_version("1.0.0"), v1_legacy={"since": parse_version("2.0.0b21"), "previously": True})
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, v1_legacy=False):
|
||||
"""actual remoting is done via self.call in the @api decorator"""
|
||||
|
||||
@api(since=parse_version("2.0.0a3"))
|
||||
|
|
|
|||
|
|
@ -356,14 +356,14 @@ class RepositoryServer: # pragma: no cover
|
|||
path = os.path.realpath(path)
|
||||
return path
|
||||
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=None, v1_or_v2=False):
|
||||
if v1_or_v2:
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=None, v1_legacy=False):
|
||||
if v1_legacy:
|
||||
from .legacy.repository import LegacyRepository
|
||||
|
||||
self.RepoCls = LegacyRepository
|
||||
else:
|
||||
self.RepoCls = Repository
|
||||
self.rpc_methods = self._legacy_rpc_methods if v1_or_v2 else self._rpc_methods
|
||||
self.rpc_methods = self._legacy_rpc_methods if v1_legacy else self._rpc_methods
|
||||
logging.debug("Resolving repository path %r", path)
|
||||
path = self._resolve_path(path)
|
||||
logging.debug("Resolved repository path to %r", path)
|
||||
|
|
@ -386,7 +386,7 @@ class RepositoryServer: # pragma: no cover
|
|||
else:
|
||||
raise PathNotAllowed(path)
|
||||
kwargs = dict(lock_wait=lock_wait, lock=lock, exclusive=exclusive, send_log_cb=self.send_queued_log)
|
||||
if not v1_or_v2:
|
||||
if not v1_legacy:
|
||||
kwargs["permissions"] = self.permissions
|
||||
self.repository = self.RepoCls(path, create, **kwargs)
|
||||
self.repository.__enter__() # clean exit handled by serve() method
|
||||
|
|
@ -957,8 +957,8 @@ class RemoteRepository:
|
|||
if chunkid in self.chunkid_to_msgids:
|
||||
self.ignore_responses.add(pop_preload_msgid(chunkid))
|
||||
|
||||
@api(since=parse_version("1.0.0"), v1_or_v2={"since": parse_version("2.0.0b9"), "previously": True})
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, v1_or_v2=False):
|
||||
@api(since=parse_version("1.0.0"), v1_legacy={"since": parse_version("2.0.0b21"), "previously": True})
|
||||
def open(self, path, create=False, lock_wait=None, lock=True, exclusive=False, v1_legacy=False):
|
||||
"""actual remoting is done via self.call in the @api decorator"""
|
||||
|
||||
@api(since=parse_version("2.0.0a3"))
|
||||
|
|
|
|||
|
|
@ -2,29 +2,29 @@ from unittest.mock import MagicMock, patch
|
|||
|
||||
|
||||
def test_get_repository_ssh_v1_uses_legacy_remote():
|
||||
"""get_repository picks LegacyRemoteRepository when proto=ssh and v1_or_v2=True."""
|
||||
"""get_repository picks LegacyRemoteRepository when proto=ssh and v1_legacy=True."""
|
||||
from ...archiver._common import get_repository
|
||||
|
||||
location = MagicMock()
|
||||
location.proto = "ssh"
|
||||
|
||||
with patch("borg.legacy.remote.LegacyRemoteRepository") as mock_cls:
|
||||
get_repository(location, create=False, exclusive=False, lock_wait=None, lock=True, args=None, v1_or_v2=True)
|
||||
get_repository(location, create=False, exclusive=False, lock_wait=None, lock=True, args=None, v1_legacy=True)
|
||||
|
||||
mock_cls.assert_called_once_with(location, create=False, exclusive=False, lock_wait=None, lock=True, args=None)
|
||||
|
||||
|
||||
def test_get_repository_local_v1_uses_legacy_repository(tmp_path):
|
||||
"""get_repository picks LegacyRepository for a local-style path when v1_or_v2=True."""
|
||||
"""get_repository picks LegacyRepository for a local-style path when v1_legacy=True."""
|
||||
from ...archiver._common import get_repository
|
||||
|
||||
# proto="file" with v1_or_v2=True skips the borgstore elif (which requires not v1_or_v2)
|
||||
# proto="file" with v1_legacy=True skips the borgstore elif (which requires not v1_legacy)
|
||||
# and falls to the else branch where LegacyRepository is imported.
|
||||
location = MagicMock()
|
||||
location.proto = "file"
|
||||
location.path = str(tmp_path)
|
||||
|
||||
with patch("borg.legacy.repository.LegacyRepository") as mock_cls:
|
||||
get_repository(location, create=False, exclusive=False, lock_wait=None, lock=True, args=None, v1_or_v2=True)
|
||||
get_repository(location, create=False, exclusive=False, lock_wait=None, lock=True, args=None, v1_legacy=True)
|
||||
|
||||
mock_cls.assert_called_once_with(str(tmp_path), create=False, exclusive=False, lock_wait=None, lock=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue