forked from TrueCloudLab/restic
prune: move additional option checks to repository
This commit is contained in:
parent
fc3b548625
commit
85e4021619
3 changed files with 13 additions and 9 deletions
|
@ -150,14 +150,6 @@ func runPrune(ctx context.Context, opts PruneOptions, gopts GlobalOptions, term
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
if repo.Connections() < 2 {
|
|
||||||
return errors.Fatal("prune requires a backend connection limit of at least two")
|
|
||||||
}
|
|
||||||
|
|
||||||
if repo.Config().Version < 2 && opts.RepackUncompressed {
|
|
||||||
return errors.Fatal("compression requires at least repository format version 2")
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.UnsafeNoSpaceRecovery != "" {
|
if opts.UnsafeNoSpaceRecovery != "" {
|
||||||
repoID := repo.Config().ID
|
repoID := repo.Config().ID
|
||||||
if opts.UnsafeNoSpaceRecovery != repoID {
|
if opts.UnsafeNoSpaceRecovery != repoID {
|
||||||
|
|
|
@ -35,7 +35,7 @@ func testPruneVariants(t *testing.T, unsafeNoSpaceRecovery bool) {
|
||||||
}
|
}
|
||||||
t.Run("0"+suffix, func(t *testing.T) {
|
t.Run("0"+suffix, func(t *testing.T) {
|
||||||
opts := PruneOptions{MaxUnused: "0%", unsafeRecovery: unsafeNoSpaceRecovery}
|
opts := PruneOptions{MaxUnused: "0%", unsafeRecovery: unsafeNoSpaceRecovery}
|
||||||
checkOpts := CheckOptions{ReadData: true, CheckUnused: true}
|
checkOpts := CheckOptions{ReadData: true, CheckUnused: !unsafeNoSpaceRecovery}
|
||||||
testPrune(t, opts, checkOpts)
|
testPrune(t, opts, checkOpts)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -87,6 +88,17 @@ type packInfoWithID struct {
|
||||||
func PlanPrune(ctx context.Context, opts PruneOptions, repo restic.Repository, getUsedBlobs func(ctx context.Context, repo restic.Repository) (usedBlobs restic.CountedBlobSet, err error), printer progress.Printer) (PrunePlan, PruneStats, error) {
|
func PlanPrune(ctx context.Context, opts PruneOptions, repo restic.Repository, getUsedBlobs func(ctx context.Context, repo restic.Repository) (usedBlobs restic.CountedBlobSet, err error), printer progress.Printer) (PrunePlan, PruneStats, error) {
|
||||||
var stats PruneStats
|
var stats PruneStats
|
||||||
|
|
||||||
|
if opts.UnsafeRecovery {
|
||||||
|
// prevent repacking data to make sure users cannot get stuck.
|
||||||
|
opts.MaxRepackBytes = 0
|
||||||
|
}
|
||||||
|
if repo.Connections() < 2 {
|
||||||
|
return PrunePlan{}, stats, fmt.Errorf("prune requires a backend connection limit of at least two")
|
||||||
|
}
|
||||||
|
if repo.Config().Version < 2 && opts.RepackUncompressed {
|
||||||
|
return PrunePlan{}, stats, fmt.Errorf("compression requires at least repository format version 2")
|
||||||
|
}
|
||||||
|
|
||||||
usedBlobs, err := getUsedBlobs(ctx, repo)
|
usedBlobs, err := getUsedBlobs(ctx, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PrunePlan{}, stats, err
|
return PrunePlan{}, stats, err
|
||||||
|
|
Loading…
Reference in a new issue