mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 14:38:53 +00:00
skin_streams: treat case-only report paths as one file.
On a case-insensitive volume, normcase left two spellings of a report that has not been created as two paths. The shared report-path check folds that case, and fragment_children keeps calling the same function. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -530,6 +530,22 @@ class TestCli(unittest.TestCase):
|
||||
with open(path, "rb") as fh:
|
||||
self.assertEqual(fh.read(), data)
|
||||
|
||||
def test_case_only_spelling_of_a_missing_report_is_one_path(self):
|
||||
# normcase keeps case on macOS, and samefile cannot see a file that has not been created.
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = os.path.join(tmp, "Reports")
|
||||
os.mkdir(folder)
|
||||
probe = os.path.join(folder, "Probe.tmp")
|
||||
with open(probe, "wb"):
|
||||
pass
|
||||
insensitive = os.path.exists(os.path.join(folder, "probe.tmp"))
|
||||
os.remove(probe)
|
||||
if not insensitive:
|
||||
self.skipTest("volume keeps case")
|
||||
first = os.path.join(tmp, "Reports", "out.json")
|
||||
second = os.path.join(tmp, "reports", "out.json")
|
||||
self.assertTrue(ss.same_output_path(first, second))
|
||||
|
||||
def test_json_that_is_a_directory_is_refused_before_the_scan(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path, _ = self._archive(tmp)
|
||||
|
||||
@ -45,6 +45,11 @@ import sys
|
||||
import time
|
||||
import zlib
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # -I keeps the script directory off sys.path
|
||||
from report_paths import same_report_path # noqa: E402
|
||||
|
||||
same_output_path = same_report_path
|
||||
|
||||
PAGE = 4096
|
||||
MAX_SYS = 32 * 1024 * 1024
|
||||
MAX_GFX = 224 * 1024 * 1024
|
||||
@ -450,16 +455,6 @@ def scan_archive(path, sample, log):
|
||||
return stats
|
||||
|
||||
|
||||
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 main(argv=None):
|
||||
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
ap.add_argument("inputs", nargs="+", help="RPF9 archives to scan")
|
||||
|
||||
Reference in New Issue
Block a user