Skip to content

fs: fix durations like 1d12h being rejected - #9986

Merged
ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/compound-durations
Sep 30, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/compound-durations

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

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, M and y in the list of units. A sequence that uses one of those doesn't parse:

$ rclone lsf --max-age 1d12h /tmp/x
Error: invalid argument "1d12h" for "--max-age" flag: parsing "1d12h" as fs.Duration failed: parsing time "1d12h" as "2006-01-02": cannot parse "1d12h" as "2006"

time.ParseDuration handles 2h45m and parseDurationSuffixes handles a single number with one suffix like 1.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 ageSuffixes for d/w/M/y and time.ParseDuration for everything else, and rejects a total too long to fit in a time.Duration. Everything that parsed before takes the same path as before. I've also added 1d12h to 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 quicktest matches master (cmd/gitannex fails on both, no git-annex here) and golangci-lint run ./fs/ reports 0 issues. With the built binary, --max-age 1d12h lists a file touched 30h ago and skips one touched 48h ago.

Linked issue

None.

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • This Pull Request is ready for review.

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.
@r0h1tb
r0h1tb requested a review from ncw as a code owner September 26, 2026 23:26

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this very old bug!

@ncw
ncw merged commit d8794f8 into rclone:master Sep 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants