Merge pull request #7044 from ThomasWaldmann/repoobj-fixes

repoobj: mutate meta + misc minor fixes / updates
This commit is contained in:
TW 2022-09-21 11:55:41 +02:00 committed by GitHub
commit 600606897e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -35,7 +35,6 @@ class RepoObj:
) -> bytes:
assert isinstance(id, bytes)
assert isinstance(meta, dict)
meta = dict(meta) # make a copy, so call arg is not modified
assert isinstance(data, (bytes, memoryview))
assert compress or size is not None and ctype is not None and clevel is not None
if compress:
@ -115,14 +114,22 @@ class RepoObj1: # legacy
def id_hash(self, data: bytes) -> bytes:
return self.key.id_hash(data)
def format(self, id: bytes, meta: dict, data: bytes, compress: bool = True, size: int = None) -> bytes:
def format(
self,
id: bytes,
meta: dict,
data: bytes,
compress: bool = True,
size: int = None,
ctype: int = None,
clevel: int = None,
) -> bytes:
assert isinstance(id, bytes)
assert meta == {}
assert isinstance(data, (bytes, memoryview))
assert compress or size is not None
assert compress or size is not None
assert compress or size is not None and ctype is not None and clevel is not None
if compress:
assert size is None
assert size is None or size == len(data)
meta, data_compressed = self.compressor.compress(meta, data)
else:
assert isinstance(size, int)
@ -130,6 +137,9 @@ class RepoObj1: # legacy
data_encrypted = self.key.encrypt(id, data_compressed)
return data_encrypted
def parse_meta(self, id: bytes, cdata: bytes) -> dict:
raise NotImplementedError("parse_meta is not available for RepoObj1")
def parse(self, id: bytes, cdata: bytes, decompress: bool = True) -> tuple[dict, bytes]:
assert isinstance(id, bytes)
assert isinstance(cdata, bytes)

View File

@ -78,7 +78,7 @@ def test_borg1_borg2_transition(key):
# note: as we did not decompress, we do not have "size" and we need to get it from somewhere else.
# here, we just use len_data. for borg transfer, we also know the size from another metadata source.
borg2_cdata = repo_objs2.format(
id, meta1, compr_data1[2:], compress=False, size=len_data, ctype=meta1["ctype"], clevel=meta1["clevel"]
id, dict(meta1), compr_data1[2:], compress=False, size=len_data, ctype=meta1["ctype"], clevel=meta1["clevel"]
)
meta2, data2 = repo_objs2.parse(id, borg2_cdata)
assert data2 == data