Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions tests/test_report_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

# 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",
"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.
LEGACY_COPIES = {"navmesh_decode"}
"glb_inspect", "meshlet_page", "navmesh_decode", "navmesh_index", "rpf_probe", "tile_probe",
"world_index", "world_lights_paths", "world_names")
# No tool carries its own copy any more: import report_paths instead. Do not add to this list.
LEGACY_COPIES = set()


def touch(path):
Expand Down Expand Up @@ -259,7 +258,7 @@ def test_no_new_copies_of_same_report_path(self):

def test_tools_still_expose_same_report_path(self):
# gamedata_xml.py and others call it by this name (and tests or sibling tools may import it).
for tool in ("gamedata_index", "gamedata_xml", "navmesh_index", "world_index"):
for tool in ("gamedata_index", "gamedata_xml", "navmesh_decode", "navmesh_index", "world_index"):
with self.subTest(tool=tool):
module = __import__(tool)
self.assertIs(module.same_report_path, report_paths.same_report_path)
Expand Down
38 changes: 1 addition & 37 deletions tools/navmesh_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
import struct
import sys
import time
import unicodedata
import zlib
from collections import Counter
from collections.abc import Iterator

ROOT = os.path.dirname(os.path.abspath(__file__))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
from report_paths import same_report_path # noqa: E402
from zero_span import gap_split # noqa: E402

BASE = 0x50000000
Expand Down Expand Up @@ -1048,42 +1048,6 @@ def _offset(text):
return value


_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):
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


def main(argv=None):
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("input", help="RPF9 archive (navmeshes.rpf) or directory of carved streams")
Expand Down