mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 16:18:37 +00:00
bink_names: reject duplicate stream locations before assigning names
This commit is contained in:
@ -565,6 +565,24 @@ class TestReportErrors(unittest.TestCase):
|
||||
code = names_mod.main([source, "--mount", xml, "--out", out])
|
||||
return code, err.getvalue(), out
|
||||
|
||||
def test_duplicate_stream_locations_are_not_named_twice(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
movie = stream(12, source="clips/one.rpf")
|
||||
other = stream(12, source="clips/two.rpf")
|
||||
index = self.write(tmp, "index.json", json.dumps({"streams": [other, movie]}))
|
||||
self.assertEqual(len(names_mod.load_streams(index)), 2)
|
||||
duplicate = dict(movie, source="clips\\one.rpf", frames=movie["frames"] + 1)
|
||||
self.write(tmp, "index.json", json.dumps({"streams": [movie, other, duplicate]}))
|
||||
output = self.write(tmp, "names.csv", "previous report")
|
||||
xml = self.write(tmp, "list.xml", mount_xml(["a.bk2", "b.bk2", "c.bk2"]))
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err), contextlib.redirect_stdout(io.StringIO()):
|
||||
rc = names_mod.main([index, "--mount", xml, "--out", output])
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("duplicate stream location", err.getvalue())
|
||||
with open(output, encoding="utf-8") as fh:
|
||||
self.assertEqual(fh.read(), "previous report")
|
||||
|
||||
def test_bad_sources_are_rejected(self):
|
||||
# (extension, contents, expected error fragment or None to only require the path)
|
||||
cases = [
|
||||
|
||||
@ -183,6 +183,10 @@ def load_streams(source, skip_report=None):
|
||||
out[-1]["source"] = out[-1]["source"].replace("\\", "/") # an older Windows index wrote "\"
|
||||
# A directory of carved files sorts by file name; carves name files by archive offset.
|
||||
out.sort(key=lambda r: (r["source"], r["offset"]))
|
||||
for i in range(1, len(out)):
|
||||
prev, curr = out[i - 1], out[i]
|
||||
if prev["source"] == curr["source"] and prev["offset"] == curr["offset"]:
|
||||
raise ValueError(f"duplicate stream location: {curr['source']} at offset {curr['offset']}")
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user