Skip to content

Keep the requested number of rotated file generations - #483

Closed
oyeong011 wants to merge 1 commit into
mahmoud:masterfrom
oyeong011:fix/rotate-file-retain-generations
Closed

oyeong011 wants to merge 1 commit into
mahmoud:masterfrom
oyeong011:fix/rotate-file-retain-generations

Conversation

@oyeong011

Copy link
Copy Markdown

rotate_file(path, keep=1) currently deletes the backup it just created, leaving no copy of the file. For larger values it retains keep - 1 generations instead of the requested count.

Remove the oldest generation before the descending rename sequence. This lets the new last generation survive. Update the two full-rotation tests to verify all five retained contents (including replacement of a pre-existing fifth backup), and add repeated-rotation tests for keep=1, 2, and 5, with and without extensions.

Fixes #479.

Validation:

  • Before: 8 fileutils scenarios fail; keep=1 leaves an empty directory.
  • After: 678 tests and doctests pass (python -m pytest --doctest-modules boltons tests -q).
  • Actual temporary files preserve the latest backup, replace the oldest on subsequent rotations, and remain unchanged when the source is missing or keep=0 is rejected.
  • Full suite tested locally on macOS with CPython 3.12.13; focused review tests also passed on Python 3.14. Windows was not tested.

This branch is independent of #482. AI assistance was used for implementation and tests; before/after filesystem behavior was verified locally.

Expire the oldest backup before shifting filenames so the newly rotated
last generation is retained, including the keep=1 boundary.

Tested: 678 tests and doctests; real-file rotation with keep=1
Confidence: high
Scope-risk: narrow
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #610 (see the PR description for credit). Thanks for the report and the repro.

@mahmoud mahmoud closed this Oct 25, 2026
blebo pushed a commit to blebo/boltons that referenced this pull request Nov 1, 2026
…oud#483)

Workstream-Session-Id: 01a1743e-7af6-7000-999f-e3695b3279ef
Workstream-Plan-Id: 2026-10-25-7167a83d96
blebo pushed a commit to blebo/boltons that referenced this pull request Nov 1, 2026
…hmoud#608 to 26.3.0

Workstream-Session-Id: 01a1743e-7af6-7000-999f-e3695b3279ef
Workstream-Plan-Id: 2026-10-25-7167a83d96
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.

fileutils.rotate_file(keep=1) deletes the file it just rotated; keep=N retains N-1 generations

2 participants