mirror of https://github.com/borgbackup/borg.git
Merge pull request #7044 from ThomasWaldmann/repoobj-fixes
repoobj: mutate meta + misc minor fixes / updates
This commit is contained in:
commit
600606897e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue