Skip to content

b2: add --max-age option to cleanup-hidden command#9446

Open
pkolbus wants to merge 2 commits into
rclone:masterfrom
pkolbus:b2-delete-hidden-maxage
Open

b2: add --max-age option to cleanup-hidden command#9446
pkolbus wants to merge 2 commits into
rclone:masterfrom
pkolbus:b2-delete-hidden-maxage

Conversation

@pkolbus

@pkolbus pkolbus commented May 19, 2026

Copy link
Copy Markdown

What is the purpose of this change?

Allow preserving recently hidden files during a cleanup-hidden operation, while deleting files that have been hidden longer. This allows (for example):

  • forcing a cleanup when a bucket's lifecycle settings aren't effective
  • to immediately apply more aggressive lifecycle settings, reducing space used and cost

The implementation takes advantage of code shared with cleanup, which already has a max-age option. However in this case the default is 0 for backward compatibility.

Note: Automated tests are not added, as any would be fragile. b2_internal_test.go isn't architected for precise control of timing, only that file versions are created a couple of seconds apart. The implementation of b2's backend cleanup also does not have max-age tests. That said, I have tested manually with -vv; the log messages and file version listings confirm that this works.

Was the change discussed in an issue or in the forum before?

No

Checklist

  • I have read the contribution guidelines.
  • 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.
  • I'm done, this Pull Request is ready for review :-)

@pkolbus pkolbus force-pushed the b2-delete-hidden-maxage branch 2 times, most recently from c48b6ac to ff503f3 Compare May 19, 2026 23:00
@pkolbus pkolbus changed the title b2: support cleanup-hidden --max-age b2: add --max-age option to cleanup-hidden command May 19, 2026
@pkolbus pkolbus marked this pull request as ready for review May 19, 2026 23:15
Add a max-age option to the cleanup-hidden command; this deletes
files hidden more than --max-age ago. For backward compatibility, the
default is 0 (delete all hidden files).
@pkolbus pkolbus force-pushed the b2-delete-hidden-maxage branch from ff503f3 to 83e9066 Compare May 24, 2026 11:39
Comment thread docs/content/b2.md Outdated

@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.

Hi.

Thanks for doing this.

I think there are a couple of correctness issues we need to address - see inline.

Thank you :-)

Comment thread backend/b2/b2.go

func (f *Fs) cleanupHiddenCommand(ctx context.Context, name string, arg []string, opt map[string]string) (out any, err error) {
return nil, f.cleanUp(ctx, true, false, 0)
maxAge := defaultMaxAge

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.

This changes the default from unset to defaultMaxAge which is a behaviour change.

I think you want maxAge := time.Duration(0) here

Comment thread backend/b2/b2.go
// Check current version of the file
if deleteHidden && object.Action == "hide" {
fs.Debugf(remote, "Deleting current version (id %q) as it is a hide marker", object.ID)
if deleteHidden && object.Action == "hide" && isUploadStale(object.UploadTimestamp) {

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.

This is changing the behaviour of the Purge and Cleanup methods isn't it?

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