mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
rootsig_census: reserve root and disasm index.json paths before first write (ROOTSIG-CENSUS-JSON-GUARD)
This commit is contained in:
@ -305,6 +305,20 @@ class TestCensus(unittest.TestCase):
|
||||
with open(path, "rb") as fh:
|
||||
self.assertEqual(fh.read(), snapshots[path])
|
||||
|
||||
def test_json_refuses_manifest_paths_before_either_file_exists(self):
|
||||
disasm = os.path.join(self.tmp.name, "disasm")
|
||||
os.mkdir(disasm)
|
||||
for directory in (self.tmp.name, disasm):
|
||||
with self.subTest(directory=directory):
|
||||
target = os.path.join(directory, "index.json")
|
||||
self.assertFalse(os.path.exists(target))
|
||||
run = subprocess.run([sys.executable, "-I", TOOL, self.tmp.name, "--disasm", disasm, "--json", target],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(run.returncode, 2, run.stderr)
|
||||
self.assertIn("would overwrite an input file", run.stderr)
|
||||
self.assertEqual(run.stdout, "")
|
||||
self.assertFalse(os.path.exists(target))
|
||||
|
||||
def test_json_guard_delegates_to_shared_same_report_path(self):
|
||||
self.write("sig", [(b"RTS0", rts0(params=[("cbv", 0)]))], user_sgprs=8)
|
||||
out = os.path.join(self.tmp.name, "ALIAS.JSON")
|
||||
|
||||
@ -295,11 +295,8 @@ def summarize(rows):
|
||||
|
||||
|
||||
def _census_inputs(root, disasm=None):
|
||||
"""Existing files in `root` (and `disasm` when given) that `--json` must not overwrite."""
|
||||
paths = []
|
||||
manifest = os.path.join(root, "index.json")
|
||||
if os.path.isfile(manifest):
|
||||
paths.append(manifest)
|
||||
"""Manifest paths and existing inputs that `--json` must not overwrite."""
|
||||
paths = [os.path.join(root, "index.json")]
|
||||
with os.scandir(root) as entries:
|
||||
for entry in entries:
|
||||
if entry.name.lower().endswith(".dxbc") and entry.is_file():
|
||||
@ -311,9 +308,7 @@ def _census_inputs(root, disasm=None):
|
||||
if entry.name.lower().endswith(".json") and entry.is_file():
|
||||
paths.append(entry.path)
|
||||
if disasm:
|
||||
disasm_manifest = os.path.join(disasm, "index.json")
|
||||
if os.path.isfile(disasm_manifest):
|
||||
paths.append(disasm_manifest)
|
||||
paths.append(os.path.join(disasm, "index.json"))
|
||||
with os.scandir(disasm) as entries:
|
||||
for entry in entries:
|
||||
if entry.name.lower().endswith(".s") and entry.is_file():
|
||||
|
||||
Reference in New Issue
Block a user