(ctx context.Context, rep repo.Repository)
| 572 | } |
| 573 | |
| 574 | func (c *App) maybeRunMaintenance(ctx context.Context, rep repo.Repository) error { |
| 575 | if !c.enableAutomaticMaintenance { |
| 576 | return nil |
| 577 | } |
| 578 | |
| 579 | if rep.ClientOptions().ReadOnly { |
| 580 | return nil |
| 581 | } |
| 582 | |
| 583 | dr, ok := rep.(repo.DirectRepository) |
| 584 | if !ok { |
| 585 | return nil |
| 586 | } |
| 587 | |
| 588 | err := repo.DirectWriteSession(ctx, dr, repo.WriteSessionOptions{ |
| 589 | Purpose: "maybeRunMaintenance", |
| 590 | OnUpload: c.progress.UploadedBytes, |
| 591 | }, func(ctx context.Context, w repo.DirectRepositoryWriter) error { |
| 592 | return snapshotmaintenance.Run(ctx, w, maintenance.ModeAuto, false, maintenance.SafetyFull) |
| 593 | }) |
| 594 | |
| 595 | var noe maintenance.NotOwnedError |
| 596 | |
| 597 | if errors.As(err, &noe) { |
| 598 | // do not report the NotOwnedError to the user since this is automatic maintenance. |
| 599 | return nil |
| 600 | } |
| 601 | |
| 602 | return errors.Wrap(err, "error running maintenance") |
| 603 | } |
| 604 | |
| 605 | func (c *App) dangerousCommand() { |
| 606 | if c.DangerousCommands != "enabled" { |
no test coverage detected