diff --git a/core/commands/repo.go b/core/commands/repo.go index b34010e667a..0378fb271a2 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -40,6 +40,7 @@ var RepoCmd = &cmds.Command{ }, } +// GcResult is the result returned by "repo gc" command type GcResult struct { Key *cid.Cid Error string `json:",omitempty"` diff --git a/core/corerepo/gc.go b/core/corerepo/gc.go index 4bf45f8296a..39c6dd8de3a 100644 --- a/core/corerepo/gc.go +++ b/core/corerepo/gc.go @@ -125,6 +125,7 @@ func NewMultiError(errs ...error) *MultiError { return &MultiError{errs[:len(errs)-1], errs[len(errs)-1]} } +// MultiError contains the results of multiple errors. type MultiError struct { Errors []error Summary error diff --git a/pin/gc/gc.go b/pin/gc/gc.go index ccf354b4510..0ce6866952a 100644 --- a/pin/gc/gc.go +++ b/pin/gc/gc.go @@ -66,7 +66,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin. err := bs.DeleteBlock(k) if err != nil { errors = true - output <- Result{Error: &CouldNotDeleteBlockError{k, err}} + output <- Result{Error: &CannotDeleteBlockError{k, err}} //log.Errorf("Error removing key from blockstore: %s", err) // continue as error is non-fatal continue loop @@ -82,7 +82,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin. } } if errors { - output <- Result{Error: ErrCouldNotDeleteSomeBlocks} + output <- Result{Error: ErrCannotDeleteSomeBlocks} } }() @@ -103,6 +103,7 @@ func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots return nil } +// ColoredSet computes the set of nodes in the graph that are pinned by the pins in the given pinner func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffortRoots []*cid.Cid, output chan<- Result) (*cid.Set, error) { // KeySet currently implemented in memory, in the future, may be bloom filter or // disk backed to conserve memory. @@ -112,7 +113,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo links, err := ls.GetLinks(ctx, cid) if err != nil { errors = true - output <- Result{Error: &CouldNotFetchLinksError{cid, err}} + output <- Result{Error: &CannotFetchLinksError{cid, err}} } return links, nil } @@ -126,7 +127,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo links, err := ls.GetLinks(ctx, cid) if err != nil && err != dag.ErrNotFound { errors = true - output <- Result{Error: &CouldNotFetchLinksError{cid, err}} + output <- Result{Error: &CannotFetchLinksError{cid, err}} } return links, nil } @@ -147,30 +148,30 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo } if errors { - return nil, ErrCouldNotFetchAllLinks - } else { - return gcs, nil + return nil, ErrCannotFetchAllLinks } + + return gcs, nil } -var ErrCouldNotFetchAllLinks = errors.New("garbage collection aborted: could not retrieve some links") +var ErrCannotFetchAllLinks = errors.New("garbage collection aborted: could not retrieve some links") -var ErrCouldNotDeleteSomeBlocks = errors.New("garbage collection incomplete: could not delete some blocks") +var ErrCannotDeleteSomeBlocks = errors.New("garbage collection incomplete: could not delete some blocks") -type CouldNotFetchLinksError struct { +type CannotFetchLinksError struct { Key *cid.Cid Err error } -func (e *CouldNotFetchLinksError) Error() string { +func (e *CannotFetchLinksError) Error() string { return fmt.Sprintf("could not retrieve links for %s: %s", e.Key, e.Err) } -type CouldNotDeleteBlockError struct { +type CannotDeleteBlockError struct { Key *cid.Cid Err error } -func (e *CouldNotDeleteBlockError) Error() string { +func (e *CannotDeleteBlockError) Error() string { return fmt.Sprintf("could not remove %s: %s", e.Key, e.Err) }