Answer product-owner round 3: 0 🔴, 1 🟡 (0 misread); a call with a --memory of 0 anywhere passes through unchanged, so neither docker's -m 0 nor a container's grep -m 0 is dropped or overridden

This commit is contained in:
2026-10-24 11:46:56 +02:00
parent 6a2f29635e
commit ed22a48a61
3 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -41,7 +41,6 @@ def unset_swap(value: str) -> bool:
def zero(value: str) -> bool:
"""Whether a value is 0 in any unit: a -m 0 leaves memory unlimited, and would override the limit capped adds."""
return size(value) == 0
@@ -85,13 +84,14 @@ def helped(arguments: list[str]) -> bool:
def capped(arguments: list[str], share: str) -> list[str]:
"""docker's arguments, with each limit a container they make lacks added right after the subcommand.
A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0, and a --memory of 0, is dropped; every other word stays.
A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0 is dropped; every other word stays. Arguments with a --memory of 0 anywhere come back unchanged.
"""
if not unlimited(arguments):
# A -m 0 asks docker for unlimited memory, and would override an added limit; it may also be the container's own, as in grep -m 0, so it is neither dropped nor capped.
if not unlimited(arguments) or option_value(arguments, MEMORY_OPTIONS, zero):
return arguments
memory = option_value(arguments, MEMORY_OPTIONS, memory_limit)
swap = option_value(arguments, SWAP_OPTIONS, swap_limit)
rest = without(without(arguments, SWAP_OPTIONS, unset_swap), MEMORY_OPTIONS, zero)
rest = without(arguments, SWAP_OPTIONS, unset_swap)
limits = ([] if memory else ["--memory", swap or share]) + ([] if swap else ["--memory-swap", memory or share])
after = subcommand_at(rest)[-1] + 1
return [*rest[:after], *limits, *rest[after:]]