bink_index: treat case-only report paths as one file.

On a case-insensitive volume, normcase left Movies/index.json and movies/index.json as two paths, so --out could write the carve manifest. The shared report-path check refuses that spelling.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dash
2026-11-24 19:06:35 -05:00
parent 1154976d49
commit fb43ae7e5a
2 changed files with 22 additions and 10 deletions

View File

@ -360,6 +360,27 @@ class TestCommandLine(unittest.TestCase):
self.assertIn("would overwrite the carve manifest", err.getvalue())
self.assertFalse(os.path.exists(manifest))
def test_output_cannot_create_the_manifest_under_another_case(self):
# normcase keeps case on macOS, so Movies/index.json and movies/index.json used to pass as two paths
# and the second write replaced the carve manifest. APFS treats them as one name.
carve = os.path.join(self.tmp.name, "Movies")
os.makedirs(carve, exist_ok=True)
probe = os.path.join(carve, "Probe.tmp")
with open(probe, "wb"):
pass
insensitive = os.path.exists(os.path.join(carve, "probe.tmp"))
os.remove(probe)
if not insensitive:
self.skipTest("volume keeps case")
other = os.path.join(self.tmp.name, "movies", "index.json")
err = io.StringIO()
with contextlib.redirect_stderr(err), contextlib.redirect_stdout(io.StringIO()):
with self.assertRaises(SystemExit) as cm:
bink.main([carve, "--out", other])
self.assertEqual(cm.exception.code, 2)
self.assertIn("would overwrite the carve manifest", err.getvalue())
self.assertFalse(os.path.exists(os.path.join(carve, "index.json")))
def test_output_cannot_overwrite_carve_manifest(self):
carve = os.path.join(self.tmp.name, "carve")
os.makedirs(carve, exist_ok=True)

View File

@ -43,6 +43,7 @@ import tempfile
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
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 as same_output_path # noqa: E402
SIG = re.compile(rb"KB2[a-z]")
HDR = 0x2C
@ -367,16 +368,6 @@ def is_rpf_archive(path):
return len(header) >= 16 and header[1:4] == b"FPR"
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 target_problem(path):
"""None when a single named file is something this tool indexes, else a one-line reason.