From 1b33eb05f94bd0313a10291b13d78ebe483e964c Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:22:47 +0100 Subject: [PATCH 1/2] world_interior_names: no reports/ report unless --out is given The default --out wrote reports/world_interior_names.json into the folder the tool was started from, and that report holds every key's hash and distances, which the tool's own docstring calls game data to keep local. --out is now the only way to get the file; the counts on stdout are unchanged. A --out the run cannot write (a parent that is a file, a read-only folder) is now one error line and exit 2 instead of a traceback after the whole scan. --- tools/world_interior_names.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/world_interior_names.py b/tools/world_interior_names.py index 9481678d91..42550b3e75 100644 --- a/tools/world_interior_names.py +++ b/tools/world_interior_names.py @@ -378,7 +378,7 @@ def main(argv=None): ap.add_argument("--start", type=int, help="first byte of an RPF9 data-area window") ap.add_argument("--limit", type=int, help="window size in bytes (default: to the end of the archive)") ap.add_argument("--jobs", type=int, default=1, help="parallel windows over an RPF9 archive (default 1)") - ap.add_argument("--out", default=os.path.join("reports", "world_interior_names.json")) + ap.add_argument("--out", help="JSON report of every key (default: no report; it holds game data, so keep it local)") a = ap.parse_args(argv) for p in (a.path, a.names): if not os.path.exists(p): @@ -389,11 +389,11 @@ def main(argv=None): ap.error("--start must not be negative") if a.limit is not None and a.limit < 1: ap.error("--limit must be at least 1 byte") # 0 would scan nothing and report every count as 0 - out_abs = os.path.abspath(a.out) - if same_report_path(a.out, a.path) or same_report_path(a.out, a.names) or _inside(a.path, out_abs): + out_abs = os.path.abspath(a.out) if a.out else None + if out_abs and (same_report_path(a.out, a.path) or same_report_path(a.out, a.names) or _inside(a.path, out_abs)): print("world_interior_names.py: --out would overwrite an input: %s" % a.out, file=sys.stderr) return 2 - if os.path.isdir(a.out): + if out_abs and os.path.isdir(a.out): print("world_interior_names.py: --out is a directory: %s" % a.out, file=sys.stderr) return 2 try: @@ -407,9 +407,14 @@ def main(argv=None): print("world_interior_names.py: %s" % why, file=sys.stderr) return 2 summary, rows = resolve(names, scan(a.path, a.start, a.limit, a.jobs), duplicate_keys, malformed) - os.makedirs(os.path.dirname(out_abs), exist_ok=True) - with open(a.out, "w", encoding="utf-8", newline="\n") as f: - json.dump({"summary": summary, "keys": rows}, f, indent=1, sort_keys=True) + if a.out: + try: + os.makedirs(os.path.dirname(out_abs), exist_ok=True) + with open(a.out, "w", encoding="utf-8", newline="\n") as f: + json.dump({"summary": summary, "keys": rows}, f, indent=1, sort_keys=True) + except OSError as exc: # a report path the run cannot write is one line, not a traceback + print("world_interior_names.py: --out %s: %s" % (a.out, exc.strerror or exc), file=sys.stderr) + return 2 print(json.dumps(summary, indent=1, sort_keys=True)) return 0 From bfed3108aab11a3d82cd729684dce9f9491192d8 Mon Sep 17 00:00:00 2001 From: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:22:50 +0100 Subject: [PATCH 2/2] tests: world_interior_names leaves no report without --out Two checks on the CLI: a run without --out writes no reports/ folder in its working directory and still prints the summary, and an --out whose parent is a file gives one stderr line and exit 2. Both failed before the tool change (the folder was created, and makedirs raised FileExistsError). --- tests/test_world_interior_names.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_world_interior_names.py b/tests/test_world_interior_names.py index 9766b35e50..1130754c02 100644 --- a/tests/test_world_interior_names.py +++ b/tests/test_world_interior_names.py @@ -391,6 +391,42 @@ def test_pool_size_goes_through_process_workers(self): self.assertEqual(asked, [70]) self.assertEqual((s["interior_names"], s["placements"]), (2, 3)) # 70 windows on 2 workers, same result + def test_no_report_is_written_without_out(self): + # The report holds game data (every key's hash and distances), so the default run must not leave it in the + # folder it is started from; it used to write reports/world_interior_names.json there. + folder = os.path.join(self.tmp.name, "carved") + os.makedirs(folder) + with open(os.path.join(folder, "a.bin"), "wb") as f: + f.write(interiors()) + cwd = os.getcwd() + os.chdir(self.tmp.name) + try: + with redirect_stdout(io.StringIO()) as so: + self.assertEqual(T.main([folder, "--names", self.names]), 0) + finally: + os.chdir(cwd) + self.assertIn("interior_names", so.getvalue()) + self.assertFalse(os.path.exists(os.path.join(self.tmp.name, "reports"))) + + def test_an_out_it_cannot_write_is_one_line(self): + folder = os.path.join(self.tmp.name, "carved") + os.makedirs(folder) + with open(os.path.join(folder, "a.bin"), "wb") as f: + f.write(interiors()) + blocker = os.path.join(self.tmp.name, "blocker") + with open(blocker, "w", encoding="utf-8") as f: + f.write("not a folder") + err = io.StringIO() + sys.stderr, saved = err, sys.stderr + try: + with redirect_stdout(io.StringIO()) as so: + self.assertEqual(T.main([folder, "--names", self.names, + "--out", os.path.join(blocker, "r.json")]), 2) + finally: + sys.stderr = saved + self.assertEqual(len(err.getvalue().strip().splitlines()), 1, err.getvalue()) + self.assertEqual(so.getvalue(), "") + def test_malformed_names_file_is_one_line(self): folder = os.path.join(self.tmp.name, "carved") os.makedirs(folder)