Repository navigation
Conversation
Fixes docker#3091 units.HumanSizeWithPrecision formats the value with %g, which renders values that round up to the next power of 1000 (e.g. 999.5MB) as "1e+03MB" instead of "1000MB". Format image sizes with a local helper that falls back to a plain integer rendering in that case, keeping the existing 3-significant-digit output everywhere else.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3091
Root cause
imageContext.Size()formats withunits.HumanSizeWithPrecision(size, 3), which formats the value with%g.%gswitches to scientific notation when the value rounds up to the next power of 1000, so 999,517,084 bytes (999.5 MB) renders as1e+03MBinstead of1000MB. Upstream go-units still has the same behaviour, so the fix belongs here.Fix
New local helper
humanSize()incli/command/formatter/image.go, used byimageContext.Size(). It mirrorsHumanSizeWithPrecision(size, 3)exactly, except when%gwould emit scientific notation it falls back to a plain integer rendering in the same unit (1000MB). Scope is the reported surface only (docker image ls); the otherHumanSizeWithPrecisioncall sites (container sizes, build cache, history, tree) are untouched.Relation to earlier attempts
I am aware of #5059, #7059 and #7064. #5059 and #7059 swap precision 3 for 4 (
HumanSize), which only moves the bug to the next boundary (9999.5 MB would render as1e+04MB) and changes displayed precision for all sizes. #7064 bumps the go-units vendor copy. This PR instead fixes the%gedge at the call site while keeping the existing 3-significant-digit output everywhere else.Tests
Added cases to
TestImageContext: 999517084 bytes ->1000MB(the reported case), 999500000 bytes ->1000MB(boundary), plus 1000000000 ->1GBand 2746000000 ->2.75GBto pin existing behaviour. Verified the new cases fail without the fix (1e+03MB) and pass with it. Fullcli/command/formatterpackage passes;gofmtandgo vetclean.