fix: cost the device prefix exactly rather than approximately
Build and publish container / build (pull_request) Successful in 3m54s
Build and publish container / build (pull_request) Successful in 3m54s
The budget subtracted the prefix length plus two, on the assumption of a leading and a trailing slash. That is right for /Music and wrong for an empty prefix, where there is only one slash -- losing a character at the card root, which is exactly where the longest paths sit. Computed from the prefix as it will actually appear instead: /Music/ costs seven characters and gives a mirror-relative budget of 253, the root costs one and gives 259. Worth being exact about because the reverse error is worse. A checker comparing mirror-relative paths against the flat 260 passes everything between 253 and 260, and those are precisely the paths closest to the edge.
This commit is contained in:
+13
-1
@@ -167,6 +167,18 @@ def fat32_safe(component):
|
||||
return cleaned or "_"
|
||||
|
||||
|
||||
def device_prefix_length(prefix):
|
||||
"""Return the on-device prefix as it will actually appear, with slashes.
|
||||
|
||||
"/Music" costs seven characters -- the leading slash, the name, and the
|
||||
separator before the mirror's own path -- while an empty prefix costs one.
|
||||
Approximating that loses a character at the root, which is precisely where
|
||||
the longest paths are.
|
||||
"""
|
||||
cleaned = prefix.strip("/")
|
||||
return f"/{cleaned}/" if cleaned else "/"
|
||||
|
||||
|
||||
def shorten_component(component, budget):
|
||||
"""Return a component of at most `budget` characters, cut from the middle.
|
||||
|
||||
@@ -783,7 +795,7 @@ def main(argv=None):
|
||||
|
||||
# The device's limit covers the whole path it will see, so what the mirror
|
||||
# may spend is that less the directory it gets copied into.
|
||||
budget = max(0, args.max_path - len(args.device_prefix.strip("/")) - 2)
|
||||
budget = max(0, args.max_path - len(device_prefix_length(args.device_prefix)))
|
||||
if args.fat32_safe:
|
||||
logger.info(
|
||||
"paths are limited to %d characters, from --max-path %d less the %r prefix",
|
||||
|
||||
Reference in New Issue
Block a user