diff --git a/tests/test_report_paths.py b/tests/test_report_paths.py index 5a22fe2cc5..a7012a354c 100644 --- a/tests/test_report_paths.py +++ b/tests/test_report_paths.py @@ -22,7 +22,7 @@ # Tools that use report_paths and must not define their own copy again. SHARED = ("anim_index", "awc_manifest", "bink_index", "gamedata_index", "gamedata_xml", "gen_d3d12_stubs", - "glb_inspect", "meshlet_page", "navmesh_index", "rpf_probe", "tile_probe", "world_index", + "glb_inspect", "meshlet_page", "navmesh_index", "rbf0_index", "rpf_probe", "tile_probe", "world_index", "world_lights_paths", "world_names") # The one tool that still carries its own copy (an open pull request edits its call site). Do not add to this list: # import report_paths instead. diff --git a/tools/rbf0_index.py b/tools/rbf0_index.py index 0041ac769d..4840e3b7ba 100644 --- a/tools/rbf0_index.py +++ b/tools/rbf0_index.py @@ -37,6 +37,7 @@ sys.path.insert(0, ROOT) from file_mode import published_mode # noqa: E402 from replace_retry import replace as replace_retry # noqa: E402 +from report_paths import same_report_path # noqa: E402 from zero_span import gap_split # noqa: E402 MAGIC = b"RBF0" @@ -542,16 +543,6 @@ def byte_count(text): return value -def same_output_path(first, second): - """True when writing ``second`` would truncate ``first`` (same file, path or hard link).""" - if os.path.normcase(os.path.realpath(first)) == os.path.normcase(os.path.realpath(second)): - return True - try: - return os.path.samefile(first, second) - except OSError: - return False - - def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument("source", help="an .rpf archive or a directory of carved streams") @@ -562,7 +553,7 @@ def main(): ap.add_argument("--all-strings", action="store_true", help="write every readable string to JSON (game data)") ap.add_argument("--quiet", action="store_true") a = ap.parse_args() - if same_output_path(a.source, a.out): + if same_report_path(a.source, a.out): ap.error("output must not overwrite the source") if a.strings < 0: ap.exit(2, f"{ap.prog}: error: argument --strings: must be 0 or more\n") @@ -577,8 +568,8 @@ def main(): try: if os.path.isdir(a.source): manifest = os.path.join(a.source, "index.json") - if same_output_path(manifest, a.out) or (os.path.isfile(a.out) and any( - same_output_path(path, a.out) for _, path in carved_streams(a.source))): + if same_report_path(manifest, a.out) or (os.path.isfile(a.out) and any( + same_report_path(path, a.out) for _, path in carved_streams(a.source))): ap.error(f"output would overwrite a carve input: {a.out}") rows, records, summary = scan_dir(a.source, string_limit=limit) else: