Repository navigation
fs: fix durations like 1d12h being rejected - #9986
Merged
Merged
Conversation
The docs describe a duration as a sequence of numbers each with a unit suffix, including d, w, M and y, but a sequence that used one of those units, such as --max-age 1d12h, failed with a confusing error about parsing it as a date. Only a single number with one of them, like 1.5d, or a sequence of the time.ParseDuration units was accepted. Parse such sequences before falling back to dates, rejecting ones too long to represent.
ncw
approved these changes
Sep 30, 2026
ncw
left a comment
Member
There was a problem hiding this comment.
Thank you for fixing this very old bug!
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.
What does this change do?
The docs describe a duration as "a, possibly signed, sequence of decimal numbers, each with optional fraction, and each with a unit suffix", with
d,w,Mandyin the list of units. A sequence that uses one of those doesn't parse:time.ParseDurationhandles2h45mandparseDurationSuffixeshandles a single number with one suffix like1.5d, so anything mixing the two falls through to date parsing and fails with a confusing message.This adds a step between the two that parses such a sequence, using
ageSuffixesford/w/M/yandtime.ParseDurationfor everything else, and rejects a total too long to fit in atime.Duration. Everything that parsed before takes the same path as before. I've also added1d12hto the examples in the docs.Tests: new cases in
TestParseDuration(1d12h,1w2d,1.5d12h,-1d12h, plus malformed and overflowing sequences), which fail on master.make quicktestmatches master (cmd/gitannexfails on both, nogit-annexhere) andgolangci-lint run ./fs/reports 0 issues. With the built binary,--max-age 1d12hlists a file touched 30h ago and skips one touched 48h ago.Linked issue
None.
Checklist