fix: accept a size list beside a size window

A profile entry that declares exact sizes and a min_size/max_size window
now accepts either, as the code it transcribes does. size_refusal let the
exact size outrank the window, so LinApple's ROMs (12288 to 65536 bytes),
the ZEsarUX QL ROM (16 KB floor) and MesenCE's BS-X.bin (32 KB floor) were
held to the one dump size. Master.dsk lists the two lone sizes the sector
image probe also takes. Truth, the core refusal message and the emulator
cards read the same rule.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:30:59 +01:00
1 parent 4d62c56730
commit 15f913d0ba
11 files changed
+134 -49

No files matched your search

+20 -14
View File
@@ -221,28 +221,34 @@ def size_fits(file_entry: dict, candidate_size: int) -> bool:
def size_refusal(file_entry: dict, candidate_size: int) -> str | None:
"""Why the entry's declared sizes turn a size away, or None.
``size`` is an exact size or the list of sizes the code accepts, and it
outranks a ``min_size``/``max_size`` range. ``size_multiple`` is a
granule the size must be a whole number of, as xemu maps any flash
image whose size is a positive multiple of 64 KiB (hw/xbox/xbox.c).
Nothing declared fits all.
``size`` is the exact size, or the list of sizes, the code accepts.
A ``min_size``/``max_size`` window declared beside it is accepted too:
LinApple's sector image probe takes 143105 to 143364 bytes plus two
lone values (SectorDiskImage.cpp), and a 1 MB BS-X dump sits inside the
32 KB floor MesenCE checks. ``size_multiple`` is a granule a size inside
the window must be a whole number of, as xemu maps any flash image whose
size is a positive multiple of 64 KiB (hw/xbox/xbox.c). Nothing declared
fits all.
"""
declared = file_entry.get("size")
if declared is not None:
allowed = declared if isinstance(declared, list) else [declared]
if candidate_size in allowed:
allowed = [] if declared is None else declared if isinstance(declared, list) else [declared]
if candidate_size in allowed:
return None
low = file_entry.get("min_size")
high = file_entry.get("max_size")
multiple = file_entry.get("size_multiple")
if low is None and high is None and not multiple:
if not allowed:
return None
accepted = ",".join(str(s) for s in sorted(allowed))
return f"size mismatch: got {candidate_size}, accepted [{accepted}]"
low = file_entry.get("min_size")
high = file_entry.get("max_size")
exact = f" or [{','.join(str(s) for s in sorted(allowed))}]" if allowed else ""
if low is not None and candidate_size < low:
return f"size too small: min {low}, got {candidate_size}"
return f"size too small: min {low}{exact}, got {candidate_size}"
if high is not None and candidate_size > high:
return f"size too large: max {high}, got {candidate_size}"
multiple = file_entry.get("size_multiple")
return f"size too large: max {high}{exact}, got {candidate_size}"
if multiple and candidate_size % int(multiple):
return f"size mismatch: got {candidate_size}, accepted multiples of {multiple}"
return f"size mismatch: got {candidate_size}, accepted multiples of {multiple}{exact}"
return None
+23 -17
View File
@@ -472,32 +472,38 @@ def _archives_not_members(files: list[dict]) -> list[dict]:
return out
def _sizes(entry: dict) -> tuple[set[int] | None, int | None, int | None]:
"""The sizes an entry admits: exact values, then a min and a max."""
def _sizes(entry: dict) -> tuple[set[int], tuple[int, float] | None]:
"""The sizes an entry admits: exact values, then its window or None.
An entry that declares no size at all admits every size, an unbounded
window. Exact sizes alone leave no window (size_refusal).
"""
raw = entry.get("size")
values = raw if isinstance(raw, list) else [raw]
exact = {int(v) for v in values if isinstance(v, int) and not isinstance(v, bool)}
low, high = entry.get("min_size"), entry.get("max_size")
return (exact or None,
low if isinstance(low, int) else None,
high if isinstance(high, int) else None)
low = low if isinstance(low, int) else None
high = high if isinstance(high, int) else None
if low is None and high is None:
return exact, None if exact else (0, float("inf"))
return exact, (low or 0, float("inf") if high is None else high)
def _sizes_clash(a: dict, b: dict) -> bool:
"""No size both entries admit, lists and ranges included."""
exact_a, low_a, high_a = _sizes(a)
exact_b, low_b, high_b = _sizes(b)
"""No size both entries admit, lists and windows included."""
exact_a, window_a = _sizes(a)
exact_b, window_b = _sizes(b)
def fits(value: int, low: int | None, high: int | None) -> bool:
return (low is None or value >= low) and (high is None or value <= high)
def inside(value: int, window: tuple[int, float] | None) -> bool:
return window is not None and window[0] <= value <= window[1]
if exact_a and exact_b:
return not exact_a & exact_b
if exact_a:
return not any(fits(v, low_b, high_b) for v in exact_a)
if exact_b:
return not any(fits(v, low_a, high_a) for v in exact_b)
return False
if exact_a & exact_b:
return False
if any(inside(v, window_b) for v in exact_a) or any(inside(v, window_a) for v in exact_b):
return False
if window_a and window_b:
return max(window_a[0], window_b[0]) > min(window_a[1], window_b[1])
return True
def _identity(entry: dict, db: dict | None) -> dict:
+7 -5
View File
@@ -1223,8 +1223,10 @@ def core_size_refusal(
if sized:
tests = sorted({check for entry in sized for check in declared_content_checks(entry)})
return f"the core's {', '.join(tests)} test turns it away"
bounds = (
f"{file_entry['size']}" if file_entry.get("size") is not None
else f"{file_entry.get('min_size', 0)} to {file_entry.get('max_size', 'any')}"
)
return f"{size} bytes, the core checks for {bounds}"
declared = file_entry.get("size")
bounds = [] if declared is None else [str(declared)]
multiple = file_entry.get("size_multiple")
if multiple or any(file_entry.get(k) is not None for k in ("min_size", "max_size")):
window = f"{file_entry.get('min_size', 0)} to {file_entry.get('max_size', 'any')}"
bounds.append(f"{window} in multiples of {multiple}" if multiple else window)
return f"{size} bytes, the core checks for {' or '.join(bounds)}"
+2 -2
View File
@@ -389,7 +389,7 @@ def _card_place_details(f: dict, profile: dict, owner: str, data_href: str) -> l
def _card_size_details(f: dict) -> list[str]:
"""The size, with its bounds."""
"""The exact sizes, then the window the code also accepts (size_refusal)."""
size = f.get("size")
fmin = f.get("min_size")
fmax = f.get("max_size")
@@ -407,7 +407,7 @@ def _card_size_details(f: dict) -> list[str]:
else:
size_str = sized(size)
if bounds:
size_str += f" ({', '.join(bounds)})"
size_str += f", or {', '.join(bounds)}"
return [f"Size: {size_str}"]
if bounds:
return [f"Size: {', '.join(bounds)}"]