Skip to content

Commit

Permalink
gc: address CR comments
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Mar 19, 2017
1 parent f66ca2f commit bfaba39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions core/corerepo/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func NewMultiError(errs ...error) *MultiError {
return &MultiError{errs[:len(errs)-1], errs[len(errs)-1]}
}

// MultiError contains the results of multiple errors. Implements the
// Error interface.
type MultiError struct {
Errors []error
Summary error
Expand Down
26 changes: 13 additions & 13 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
}
}()

Expand Down Expand Up @@ -112,7 +112,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
}
Expand All @@ -126,7 +126,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
}
Expand All @@ -147,30 +147,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)
}

0 comments on commit bfaba39

Please sign in to comment.