mirror of
https://github.com/kopia/kopia.git
synced 2026-01-02 03:27:51 -05:00
refactor(cli): cleanup cli.repositoryAccessMode (#4541)
Remove `repositoryAccessMode.mustBeConnected` It is always true. Rename `repositoryAccessMode.disableMaintenance` to `allowMaintenance`. This explicitly conveys when maintenance is allowed to run. It is related to accessing a repository in 'read-only' mode.
This commit is contained in:
30
cli/app.go
30
cli/app.go
@@ -463,28 +463,19 @@ func (c *App) directRepositoryWriteAction(act func(ctx context.Context, rep repo
|
||||
Purpose: "cli:" + c.currentActionName(),
|
||||
OnUpload: c.progress.UploadedBytes,
|
||||
}, func(ctx context.Context, dw repo.DirectRepositoryWriter) error { return act(ctx, dw) })
|
||||
}), repositoryAccessMode{
|
||||
mustBeConnected: true,
|
||||
disableMaintenance: true,
|
||||
})
|
||||
}), repositoryAccessMode{})
|
||||
}
|
||||
|
||||
func (c *App) directRepositoryReadAction(act func(ctx context.Context, rep repo.DirectRepository) error) func(ctx *kingpin.ParseContext) error {
|
||||
return c.maybeRepositoryAction(assertDirectRepository(func(ctx context.Context, rep repo.DirectRepository) error {
|
||||
return act(ctx, rep)
|
||||
}), repositoryAccessMode{
|
||||
mustBeConnected: true,
|
||||
disableMaintenance: true,
|
||||
})
|
||||
}), repositoryAccessMode{})
|
||||
}
|
||||
|
||||
func (c *App) repositoryReaderAction(act func(ctx context.Context, rep repo.Repository) error) func(ctx *kingpin.ParseContext) error {
|
||||
return c.maybeRepositoryAction(func(ctx context.Context, rep repo.Repository) error {
|
||||
return act(ctx, rep)
|
||||
}, repositoryAccessMode{
|
||||
mustBeConnected: true,
|
||||
disableMaintenance: true,
|
||||
})
|
||||
}, repositoryAccessMode{})
|
||||
}
|
||||
|
||||
func (c *App) repositoryWriterAction(act func(ctx context.Context, rep repo.RepositoryWriter) error) func(ctx *kingpin.ParseContext) error {
|
||||
@@ -496,7 +487,7 @@ func (c *App) repositoryWriterAction(act func(ctx context.Context, rep repo.Repo
|
||||
return act(ctx, w)
|
||||
})
|
||||
}, repositoryAccessMode{
|
||||
mustBeConnected: true,
|
||||
allowMaintenance: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -549,8 +540,7 @@ func (c *App) runAppWithContext(command *kingpin.CmdClause, cb func(ctx context.
|
||||
}
|
||||
|
||||
type repositoryAccessMode struct {
|
||||
mustBeConnected bool
|
||||
disableMaintenance bool
|
||||
allowMaintenance bool
|
||||
}
|
||||
|
||||
func (c *App) baseActionWithContext(act func(ctx context.Context) error) func(ctx *kingpin.ParseContext) error {
|
||||
@@ -569,8 +559,10 @@ func (c *App) baseActionWithContext(act func(ctx context.Context) error) func(ct
|
||||
|
||||
func (c *App) maybeRepositoryAction(act func(ctx context.Context, rep repo.Repository) error, mode repositoryAccessMode) func(ctx *kingpin.ParseContext) error {
|
||||
return c.baseActionWithContext(func(ctx context.Context) error {
|
||||
rep, err := c.openRepository(ctx, mode.mustBeConnected)
|
||||
if err != nil && mode.mustBeConnected {
|
||||
const requireConnected = true
|
||||
|
||||
rep, err := c.openRepository(ctx, requireConnected)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "open repository")
|
||||
}
|
||||
|
||||
@@ -578,7 +570,7 @@ func (c *App) maybeRepositoryAction(act func(ctx context.Context, rep repo.Repos
|
||||
|
||||
err = act(ctx, rep)
|
||||
|
||||
if rep != nil && err == nil && !mode.disableMaintenance {
|
||||
if rep != nil && err == nil && mode.allowMaintenance {
|
||||
if merr := c.maybeRunMaintenance(ctx, rep); merr != nil {
|
||||
log(ctx).Errorf("error running maintenance: %v", merr)
|
||||
}
|
||||
@@ -595,7 +587,7 @@ func (c *App) maybeRepositoryAction(act func(ctx context.Context, rep repo.Repos
|
||||
)
|
||||
}
|
||||
|
||||
if rep != nil && mode.mustBeConnected {
|
||||
if rep != nil {
|
||||
if cerr := rep.Close(ctx); cerr != nil {
|
||||
return errors.Wrap(cerr, "unable to close repository")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user