Skip to content
Closed
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
16 changes: 4 additions & 12 deletions tools/text_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
sys.path.insert(0, ROOT)
from file_mode import published_mode # noqa: E402
from hashdict import joaat # noqa: E402
from report_paths import same_report_path # noqa: E402

RESOURCE_MAGIC = b"0DRP"
RPF9_MAGIC = b"9FPR"
Expand Down Expand Up @@ -425,15 +426,6 @@ def _write_csv(path, fields, rows):
return n


def _same_output_path(first: str, second: str) -> bool:
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(argv=None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("sources", nargs="+", help="rpf9_carve.py directory, .rpf archive, or resource files/dirs")
Expand All @@ -447,7 +439,7 @@ def main(argv=None) -> int:
outs = [path for _, path in out_flags]
seen = []
for flag, p in out_flags:
if any(_same_output_path(p, prev) for prev in seen):
if any(same_report_path(p, prev) for prev in seen):
ap.error("outputs must be distinct files")
seen.append(p)
parent = os.path.dirname(os.path.abspath(p))
Expand All @@ -457,11 +449,11 @@ def main(argv=None) -> int:
if not os.path.exists(path):
print(f"text_tables: error: {path}: no such file or directory", file=sys.stderr)
return 2
if any(os.path.exists(o) and os.path.samefile(path, o) for o in outs):
if any(same_report_path(path, o) for o in outs):
ap.error("an output must not overwrite an input")
for source in a.sources:
index = os.path.join(source, "index.json")
if os.path.isdir(source) and os.path.isfile(index) and any(_same_output_path(index, o) for o in outs):
if os.path.isdir(source) and os.path.isfile(index) and any(same_report_path(index, o) for o in outs):
ap.error(f"an output must not overwrite an input: {index}")

scan = Scan()
Expand Down
Loading