Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/borg/archiver/debug_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions src/borg/testsuite/archiver/debug_cmds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down