Skip to content

Commit 39b2f74

Browse files
committed
gc: address CR comments
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent f66ca2f commit 39b2f74

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

core/commands/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var RepoCmd = &cmds.Command{
4040
},
4141
}
4242

43+
// GcResult is the result returned by "repo gc" command
4344
type GcResult struct {
4445
Key *cid.Cid
4546
Error string `json:",omitempty"`

core/corerepo/gc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
9191
return CollectResult(ctx, rmed, nil)
9292
}
9393

94+
// ColoredSet computes the set of nodes in the graph that are pinned by the pins in the given pinner
9495
func CollectResult(ctx context.Context, gcOut <-chan gc.Result, cb func(*cid.Cid)) error {
9596
var errors []error
9697
loop:
@@ -125,6 +126,7 @@ func NewMultiError(errs ...error) *MultiError {
125126
return &MultiError{errs[:len(errs)-1], errs[len(errs)-1]}
126127
}
127128

129+
// MultiError contains the results of multiple errors.
128130
type MultiError struct {
129131
Errors []error
130132
Summary error

pin/gc/gc.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
6666
err := bs.DeleteBlock(k)
6767
if err != nil {
6868
errors = true
69-
output <- Result{Error: &CouldNotDeleteBlockError{k, err}}
69+
output <- Result{Error: &CannotDeleteBlockError{k, err}}
7070
//log.Errorf("Error removing key from blockstore: %s", err)
7171
// continue as error is non-fatal
7272
continue loop
@@ -82,7 +82,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
8282
}
8383
}
8484
if errors {
85-
output <- Result{Error: ErrCouldNotDeleteSomeBlocks}
85+
output <- Result{Error: ErrCannotDeleteSomeBlocks}
8686
}
8787
}()
8888

@@ -112,7 +112,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
112112
links, err := ls.GetLinks(ctx, cid)
113113
if err != nil {
114114
errors = true
115-
output <- Result{Error: &CouldNotFetchLinksError{cid, err}}
115+
output <- Result{Error: &CannotFetchLinksError{cid, err}}
116116
}
117117
return links, nil
118118
}
@@ -126,7 +126,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
126126
links, err := ls.GetLinks(ctx, cid)
127127
if err != nil && err != dag.ErrNotFound {
128128
errors = true
129-
output <- Result{Error: &CouldNotFetchLinksError{cid, err}}
129+
output <- Result{Error: &CannotFetchLinksError{cid, err}}
130130
}
131131
return links, nil
132132
}
@@ -147,30 +147,30 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ls dag.LinkService, bestEffo
147147
}
148148

149149
if errors {
150-
return nil, ErrCouldNotFetchAllLinks
151-
} else {
152-
return gcs, nil
150+
return nil, ErrCannotFetchAllLinks
153151
}
152+
153+
return gcs, nil
154154
}
155155

156-
var ErrCouldNotFetchAllLinks = errors.New("garbage collection aborted: could not retrieve some links")
156+
var ErrCannotFetchAllLinks = errors.New("garbage collection aborted: could not retrieve some links")
157157

158-
var ErrCouldNotDeleteSomeBlocks = errors.New("garbage collection incomplete: could not delete some blocks")
158+
var ErrCannotDeleteSomeBlocks = errors.New("garbage collection incomplete: could not delete some blocks")
159159

160-
type CouldNotFetchLinksError struct {
160+
type CannotFetchLinksError struct {
161161
Key *cid.Cid
162162
Err error
163163
}
164164

165-
func (e *CouldNotFetchLinksError) Error() string {
165+
func (e *CannotFetchLinksError) Error() string {
166166
return fmt.Sprintf("could not retrieve links for %s: %s", e.Key, e.Err)
167167
}
168168

169-
type CouldNotDeleteBlockError struct {
169+
type CannotDeleteBlockError struct {
170170
Key *cid.Cid
171171
Err error
172172
}
173173

174-
func (e *CouldNotDeleteBlockError) Error() string {
174+
func (e *CannotDeleteBlockError) Error() string {
175175
return fmt.Sprintf("could not remove %s: %s", e.Key, e.Err)
176176
}

0 commit comments

Comments
 (0)