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
6 changes: 3 additions & 3 deletions tests/test_report_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import report_paths # noqa: E402

# 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")
SHARED = ("anim_index", "awc_manifest", "bink_index", "bvh_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"}
Expand Down
42 changes: 7 additions & 35 deletions tools/bvh_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
import sys
import tempfile
import time
import unicodedata
import zlib
from contextlib import suppress

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from file_mode import published_mode # noqa: E402
from report_paths import path_key # noqa: E402
from report_paths import same_report_path # noqa: E402

ROOT = os.path.dirname(os.path.abspath(__file__))
if ROOT not in sys.path:
Expand Down Expand Up @@ -473,45 +474,16 @@ 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_output_path(first, second):
if _path_key(first) == _path_key(second):
return True
try:
return os.path.samefile(first, second)
except OSError:
return False
"""True when writing ``second`` would truncate ``first``: one name (case-folded on a folding volume) or one
file through a hard link. `tools/report_paths.same_report_path` owns that answer; this keeps the name the rest
of the tool and `tests/test_report_path_case.py` call."""
return same_report_path(first, second)


def _inside(path, folder):
"""True when `path` is `folder` or lies below it, compared as the report check compares paths."""
path, folder = _path_key(path), _path_key(folder)
path, folder = path_key(path), path_key(folder)
try:
return os.path.commonpath([path, folder]) == folder
except ValueError: # different drives on Windows
Expand Down
Loading