2
2
mirror of https://github.com/octoleo/restic.git synced 2024-10-31 19:02:32 +00:00

Improve error message for orphaned pack files

This commit is contained in:
Alexander Neumann 2018-04-07 10:07:54 +02:00
parent 63a0913e6e
commit 1c1fede399
2 changed files with 22 additions and 2 deletions

View File

@ -197,7 +197,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
} }
if dupFound { if dupFound {
Printf("\nrun `restic rebuild-index' to correct this\n") Printf("This is non-critical, you can run `restic rebuild-index' to correct this\n")
} }
if len(errs) > 0 { if len(errs) > 0 {
@ -208,16 +208,26 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
} }
errorsFound := false errorsFound := false
orphanedPacks := 0
errChan := make(chan error) errChan := make(chan error)
Verbosef("check all packs\n") Verbosef("check all packs\n")
go chkr.Packs(gopts.ctx, errChan) go chkr.Packs(gopts.ctx, errChan)
for err := range errChan { for err := range errChan {
if checker.IsOrphanedPack(err) {
orphanedPacks++
Verbosef("%v\n", err)
continue
}
errorsFound = true errorsFound = true
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
} }
if orphanedPacks > 0 {
Verbosef("%d additional files were found in the repo, which likely contain duplicate data.\nYou can run `restic prune` to correct this.\n", orphanedPacks)
}
Verbosef("check snapshots, trees and blobs\n") Verbosef("check snapshots, trees and blobs\n")
errChan = make(chan error) errChan = make(chan error)
go chkr.Structure(gopts.ctx, errChan) go chkr.Structure(gopts.ctx, errChan)

View File

@ -181,7 +181,17 @@ type PackError struct {
} }
func (e PackError) Error() string { func (e PackError) Error() string {
return "pack " + e.ID.String() + ": " + e.Err.Error() return "pack " + e.ID.Str() + ": " + e.Err.Error()
}
// IsOrphanedPack returns true if the error describes a pack which is not
// contained in any index.
func IsOrphanedPack(err error) bool {
if e, ok := errors.Cause(err).(PackError); ok && e.Orphaned {
return true
}
return false
} }
// Packs checks that all packs referenced in the index are still available and // Packs checks that all packs referenced in the index are still available and