Skip to content

Commit c181845

Browse files
Merge pull request #9393 from mr-raj12/fix-debug-format-obj-robj-type
debug format-obj: support all repo object types, fixes #9391
2 parents eb82eeb + be42fdf commit c181845

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/borg/archiver/debug_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ def do_debug_format_obj(self, args, repository, manifest):
265265
meta = json.load(f)
266266

267267
repo_objs = manifest.repo_objs
268-
# TODO: support misc repo object types other than ROBJ_FILE_STREAM
269-
data_encrypted = repo_objs.format(id=id, meta=meta, data=data, ro_type=ROBJ_FILE_STREAM)
268+
ro_type = meta.pop("type", ROBJ_FILE_STREAM)
269+
data_encrypted = repo_objs.format(id=id, meta=meta, data=data, ro_type=ro_type)
270270

271271
with open(args.object_path, "wb") as f:
272272
f.write(data_encrypted)

src/borg/testsuite/archiver/debug_cmds_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ def test_debug_id_hash_format_put_get_parse_obj(archivers, request):
123123
assert meta_read.get("clevel") == c.compressor.level
124124

125125

126+
def test_debug_format_obj_respects_type(archivers, request):
127+
"""Test format-obj uses the type from metadata JSON, not just ROBJ_FILE_STREAM."""
128+
archiver = request.getfixturevalue(archivers)
129+
cmd(archiver, "repo-create", RK_ENCRYPTION)
130+
data = b"some data" * 100
131+
meta_dict = {"some": "property", "type": ROBJ_ARCHIVE_STREAM}
132+
meta = json.dumps(meta_dict).encode()
133+
create_regular_file(archiver.input_path, "data.bin", contents=data)
134+
create_regular_file(archiver.input_path, "meta.json", contents=meta)
135+
output = cmd(archiver, "debug", "id-hash", "input/data.bin")
136+
id_hash = output.strip()
137+
cmd(archiver, "debug", "format-obj", id_hash, "input/data.bin", "input/meta.json", "input/repoobj.bin")
138+
output = cmd(archiver, "debug", "put-obj", id_hash, "input/repoobj.bin")
139+
assert id_hash in output
140+
output = cmd(archiver, "debug", "get-obj", id_hash, "output/object.bin")
141+
assert id_hash in output
142+
cmd(archiver, "debug", "parse-obj", id_hash, "output/object.bin", "output/data.bin", "output/meta.json")
143+
with open("output/meta.json") as f:
144+
meta_read = json.load(f)
145+
assert meta_read["type"] == ROBJ_ARCHIVE_STREAM
146+
147+
126148
def test_debug_dump_manifest(archivers, request):
127149
archiver = request.getfixturevalue(archivers)
128150
create_regular_file(archiver.input_path, "file1", size=1024 * 80)

0 commit comments

Comments
 (0)