mirror of
https://github.com/kopia/kopia.git
synced 2026-01-22 05:18:06 -05:00
* cli: fixed remaining testability indirections for output and logging * cli: added cli.RunSubcommand() which is used in testing to execute a subcommand in the same process * tests: refactored most e2e tests to invoke kopia subcommands in-process * Makefile: enable code coverage for cli/ and internal/ * testing: pass 'testing' tag to unit tests which uses much faster (insecure) password hashing scheme * Makefile: push coverage from PRs again * tests: disable buffer management to reduce memory usage on ARM * cli: fixed misaligned atomic field on ARMHF also temporarily fixed statup-time benign race condition when setting default on the timeZone variable, which is the last global variable.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/repo/blob"
|
|
"github.com/kopia/kopia/repo/maintenance"
|
|
)
|
|
|
|
type commandBlobGC struct {
|
|
delete string
|
|
parallel int
|
|
prefix string
|
|
safety maintenance.SafetyParameters
|
|
|
|
svc appServices
|
|
}
|
|
|
|
func (c *commandBlobGC) setup(svc appServices, parent commandParent) {
|
|
cmd := parent.Command("gc", "Garbage-collect unused blobs")
|
|
cmd.Flag("delete", "Whether to delete unused blobs").StringVar(&c.delete)
|
|
cmd.Flag("parallel", "Number of parallel blob scans").Default("16").IntVar(&c.parallel)
|
|
cmd.Flag("prefix", "Only GC blobs with given prefix").StringVar(&c.prefix)
|
|
safetyFlagVar(cmd, &c.safety)
|
|
cmd.Action(svc.directRepositoryWriteAction(c.run))
|
|
|
|
c.svc = svc
|
|
}
|
|
|
|
func (c *commandBlobGC) run(ctx context.Context, rep repo.DirectRepositoryWriter) error {
|
|
c.svc.advancedCommand(ctx)
|
|
|
|
opts := maintenance.DeleteUnreferencedBlobsOptions{
|
|
DryRun: c.delete != "yes",
|
|
Parallel: c.parallel,
|
|
Prefix: blob.ID(c.prefix),
|
|
}
|
|
|
|
n, err := maintenance.DeleteUnreferencedBlobs(ctx, rep, opts, c.safety)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error deleting unreferenced blobs")
|
|
}
|
|
|
|
if opts.DryRun && n > 0 {
|
|
log(ctx).Infof("Pass --delete=yes to delete.")
|
|
}
|
|
|
|
return nil
|
|
}
|