check: removing orphaned packs is handled in 'optimize'

This commit is contained in:
Alexander Neumann 2015-11-08 21:24:51 +01:00
parent c4fc7b52ae
commit 43e2c9837e
1 changed files with 2 additions and 22 deletions

View File

@ -5,14 +5,12 @@ import (
"fmt"
"os"
"github.com/restic/restic/backend"
"github.com/restic/restic/checker"
)
type CmdCheck struct {
ReadData bool `long:"read-data" description:"Read data blobs" default:"false"`
RemoveOrphaned bool `long:"remove" description:"Remove data that isn't used" default:"false"`
CheckUnused bool `long:"check-unused" description:"Check for unused blobs" default:"false"`
ReadData bool `long:"read-data" description:"Read data blobs" default:"false"`
CheckUnused bool `long:"check-unused" description:"Check for unused blobs" default:"false"`
global *GlobalOptions
}
@ -81,14 +79,9 @@ func (cmd CmdCheck) Execute(args []string) error {
cmd.global.Verbosef("Check all packs\n")
go chkr.Packs(errChan, done)
foundOrphanedPacks := false
for err := range errChan {
errorsFound = true
fmt.Fprintf(os.Stderr, "%v\n", err)
if e, ok := err.(checker.PackError); ok && e.Orphaned {
foundOrphanedPacks = true
}
}
cmd.global.Verbosef("Check snapshots, trees and blobs\n")
@ -114,19 +107,6 @@ func (cmd CmdCheck) Execute(args []string) error {
}
}
if foundOrphanedPacks && cmd.RemoveOrphaned {
IDs := chkr.OrphanedPacks()
cmd.global.Verbosef("Remove %d orphaned packs... ", len(IDs))
for _, id := range IDs {
if err := repo.Backend().Remove(backend.Data, id.String()); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
}
cmd.global.Verbosef("done\n")
}
if errorsFound {
return errors.New("repository contains errors")
}