From be42fdf195ba278e36d88688537242f38e96d07a Mon Sep 17 00:00:00 2001 From: Mrityunjay Raj Date: Sat, 21 Feb 2026 06:52:41 +0530 Subject: [PATCH] debug format-obj: support all repo object types, fixes #9391 --- src/borg/archiver/debug_cmd.py | 4 ++-- .../testsuite/archiver/debug_cmds_test.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/borg/archiver/debug_cmd.py b/src/borg/archiver/debug_cmd.py index bb05c53d95..ed3d4ee51d 100644 --- a/src/borg/archiver/debug_cmd.py +++ b/src/borg/archiver/debug_cmd.py @@ -265,8 +265,8 @@ def do_debug_format_obj(self, args, repository, manifest): 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) diff --git a/src/borg/testsuite/archiver/debug_cmds_test.py b/src/borg/testsuite/archiver/debug_cmds_test.py index 811970f567..a573811c9d 100644 --- a/src/borg/testsuite/archiver/debug_cmds_test.py +++ b/src/borg/testsuite/archiver/debug_cmds_test.py @@ -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)