From 0df022fa6d9c445b24856c3fcd3fb3e6f00e2703 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 30 Apr 2022 20:27:31 +0200 Subject: [PATCH] check: Print full ids The short ids are not always unique. In addition, recovering from damages is easier when having the full ids as that makes it easier to access the corresponding files. --- changelog/unreleased/pull-3729 | 6 ++++++ internal/checker/checker.go | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 changelog/unreleased/pull-3729 diff --git a/changelog/unreleased/pull-3729 b/changelog/unreleased/pull-3729 new file mode 100644 index 000000000..cb69f94e2 --- /dev/null +++ b/changelog/unreleased/pull-3729 @@ -0,0 +1,6 @@ +Enhancement: Include full IDs in `check` warnings + +To repair or inspect a damaged repository, it is often necessary to use the full IDs of objects stored in the repository. +The output of check now includes full IDs instead of their shortened variant. + +https://github.com/restic/restic/pull/3729 diff --git a/internal/checker/checker.go b/internal/checker/checker.go index a31235fae..6f8c8cdc2 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -64,7 +64,7 @@ type ErrDuplicatePacks struct { } func (e *ErrDuplicatePacks) Error() string { - return fmt.Sprintf("pack %v contained in several indexes: %v", e.PackID.Str(), e.Indexes) + return fmt.Sprintf("pack %v contained in several indexes: %v", e.PackID, e.Indexes) } // ErrOldIndexFormat is returned when an index with the old format is @@ -74,7 +74,7 @@ type ErrOldIndexFormat struct { } func (err *ErrOldIndexFormat) Error() string { - return fmt.Sprintf("index %v has old format", err.ID.Str()) + return fmt.Sprintf("index %v has old format", err.ID) } func (c *Checker) LoadSnapshots(ctx context.Context) error { @@ -92,11 +92,11 @@ func (c *Checker) LoadIndex(ctx context.Context) (hints []error, errs []error) { debug.Log("process index %v, err %v", id, err) if oldFormat { - debug.Log("index %v has old format", id.Str()) + debug.Log("index %v has old format", id) hints = append(hints, &ErrOldIndexFormat{id}) } - err = errors.Wrapf(err, "error loading index %v", id.Str()) + err = errors.Wrapf(err, "error loading index %v", id) if err != nil { errs = append(errs, err) @@ -161,7 +161,7 @@ type PackError struct { } func (e *PackError) Error() string { - return "pack " + e.ID.Str() + ": " + e.Err.Error() + return "pack " + e.ID.String() + ": " + e.Err.Error() } // IsOrphanedPack returns true if the error describes a pack which is not @@ -242,7 +242,7 @@ func (e Error) Error() string { } if !e.TreeID.IsNull() { - return "tree " + e.TreeID.Str() + ": " + e.Err.Error() + return "tree " + e.TreeID.String() + ": " + e.Err.Error() } return e.Err.Error() @@ -255,7 +255,7 @@ type TreeError struct { } func (e *TreeError) Error() string { - return fmt.Sprintf("tree %v: %v", e.ID.Str(), e.Errors) + return fmt.Sprintf("tree %v: %v", e.ID, e.Errors) } // checkTreeWorker checks the trees received and sends out errors to errChan. @@ -525,11 +525,11 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r if err != nil { // failed to load the pack file, return as further checks cannot succeed anyways debug.Log(" error streaming pack: %v", err) - return errors.Errorf("pack %v failed to download: %v", err) + return errors.Errorf("pack %v failed to download: %v", id, err) } if !hash.Equal(id) { debug.Log("Pack ID does not match, want %v, got %v", id, hash) - return errors.Errorf("Pack ID does not match, want %v, got %v", id.Str(), hash.Str()) + return errors.Errorf("Pack ID does not match, want %v, got %v", id, hash) } blobs, hdrSize, err := pack.List(r.Key(), bytes.NewReader(hdrBuf), int64(len(hdrBuf))) @@ -553,13 +553,13 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID, blobs []r } } if !idxHas { - errs = append(errs, errors.Errorf("Blob %v is not contained in index or position is incorrect", blob.ID.Str())) + errs = append(errs, errors.Errorf("Blob %v is not contained in index or position is incorrect", blob.ID)) continue } } if len(errs) > 0 { - return errors.Errorf("pack %v contains %v errors: %v", id.Str(), len(errs), errs) + return errors.Errorf("pack %v contains %v errors: %v", id, len(errs), errs) } return nil