mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 17:48:40 +00:00
same_report_path was copied into ten tools, and each new "refuse an output that overwrites an input" change added another copy or a variant. Four copies (anim_index, gamedata_index, gamedata_xml, navmesh_decode) also folded case and accents on a case-insensitive macOS volume (through _path_key), the other six did not, so the same report pair was refused by one tool and written by another. tools/report_paths.py holds one version (the stricter one: realpath, normcase, case-folded NFD on a case-insensitive volume, then os.path.samefile) and awc_manifest, gamedata_index, gamedata_xml, navmesh_index, rpf_probe, tile_probe and world_names import it. The tools keep exposing the name same_report_path. On Windows and Linux nothing changes; on macOS the five tools that lacked the case/accent step now refuse a case-only alias of a report that doesn't exist yet, as the other five already did. anim_index, navmesh_decode and world_lights_paths keep their copy for now because open pull requests edit them (#2051, #2050, #2052, #2107); tests/test_report_paths.py fails if any other tool adds a copy. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SAjLH2L6R72dBvVaRG8hka
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""Do two report paths name the same file? One answer for the tools that refuse an output that would overwrite
|
|
an input or another output.
|
|
|
|
from report_paths import same_report_path # after sys.path.insert(0, <this folder>), as -I needs
|
|
|
|
`same_report_path(first, second)` is true when the two paths resolve to one name (`realpath`, then `normcase`, and on a
|
|
case-insensitive macOS volume also case-folded and with composed and decomposed accents treated alike) or when both
|
|
exist and `os.path.samefile` says they are one file (a hard link, another spelling the name rules missed). Neither
|
|
path has to exist: two report paths that don't exist yet still collide when they differ only in case on a volume that
|
|
ignores case. Standard library only; no game data.
|
|
"""
|
|
import os
|
|
import sys
|
|
import unicodedata
|
|
|
|
_PC_CASE_SENSITIVE = 11 # <sys/unistd.h> on macOS; os.pathconf_names doesn't list it
|
|
|
|
|
|
def case_insensitive_volume(path):
|
|
"""True when the volume that will hold `path` ignores letter case, as macOS's default APFS volume does.
|
|
os.path.normcase folds case only on Windows, so on macOS `R.json` and `r.json` would pass as two reports."""
|
|
if sys.platform != "darwin":
|
|
return False
|
|
while not os.path.exists(path):
|
|
parent = os.path.dirname(path)
|
|
if parent == path:
|
|
break
|
|
path = parent
|
|
try:
|
|
return os.pathconf(path, _PC_CASE_SENSITIVE) == 0
|
|
except (OSError, ValueError):
|
|
return True # the macOS default; folding can only refuse a pair, never overwrite one
|
|
|
|
|
|
def path_key(path):
|
|
"""A name two spellings of one path share: realpath, normcase, and on a case-insensitive volume case-folded NFD."""
|
|
path = os.path.normcase(os.path.realpath(path))
|
|
if case_insensitive_volume(path):
|
|
# APFS and HFS+ also treat composed and decomposed accents as one name.
|
|
path = unicodedata.normalize("NFD", path.casefold())
|
|
return path
|
|
|
|
|
|
def same_report_path(first, second):
|
|
if path_key(first) == path_key(second):
|
|
return True
|
|
try:
|
|
return os.path.samefile(first, second)
|
|
except OSError:
|
|
return False
|