debug format-obj: support all repo object types, fixes #9391

This commit is contained in:
Mrityunjay Raj 2026-02-21 06:52:41 +05:30
parent eb82eeba05
commit be42fdf195
2 changed files with 24 additions and 2 deletions

View file

@ -265,8 +265,8 @@ class DebugMixIn:
meta = json.load(f)
repo_objs = manifest.repo_objs
# TODO: support misc repo object types other than ROBJ_FILE_STREAM
data_encrypted = repo_objs.format(id=id, meta=meta, data=data, ro_type=ROBJ_FILE_STREAM)
ro_type = meta.pop("type", ROBJ_FILE_STREAM)
data_encrypted = repo_objs.format(id=id, meta=meta, data=data, ro_type=ro_type)
with open(args.object_path, "wb") as f:
f.write(data_encrypted)

View file

@ -123,6 +123,28 @@ def test_debug_id_hash_format_put_get_parse_obj(archivers, request):
assert meta_read.get("clevel") == c.compressor.level
def test_debug_format_obj_respects_type(archivers, request):
"""Test format-obj uses the type from metadata JSON, not just ROBJ_FILE_STREAM."""
archiver = request.getfixturevalue(archivers)
cmd(archiver, "repo-create", RK_ENCRYPTION)
data = b"some data" * 100
meta_dict = {"some": "property", "type": ROBJ_ARCHIVE_STREAM}
meta = json.dumps(meta_dict).encode()
create_regular_file(archiver.input_path, "data.bin", contents=data)
create_regular_file(archiver.input_path, "meta.json", contents=meta)
output = cmd(archiver, "debug", "id-hash", "input/data.bin")
id_hash = output.strip()
cmd(archiver, "debug", "format-obj", id_hash, "input/data.bin", "input/meta.json", "input/repoobj.bin")
output = cmd(archiver, "debug", "put-obj", id_hash, "input/repoobj.bin")
assert id_hash in output
output = cmd(archiver, "debug", "get-obj", id_hash, "output/object.bin")
assert id_hash in output
cmd(archiver, "debug", "parse-obj", id_hash, "output/object.bin", "output/data.bin", "output/meta.json")
with open("output/meta.json") as f:
meta_read = json.load(f)
assert meta_read["type"] == ROBJ_ARCHIVE_STREAM
def test_debug_dump_manifest(archivers, request):
archiver = request.getfixturevalue(archivers)
create_regular_file(archiver.input_path, "file1", size=1024 * 80)