Skip to content

Commit

Permalink
change to io.Closer
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Mar 25, 2024
1 parent 2b8b8bb commit 63d664b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/oras/internal/display/status/discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ func (DiscardHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, error)
return gt, nil
}

// StopTracking stops tracking the status of the target.
func (DiscardHandler) StopTracking() {}
// Close implements io.Closer.
func (DiscardHandler) Close() error {
return nil
}

// UpdateCopyOptions updates the copy options for the artifact push.
func (DiscardHandler) UpdateCopyOptions(opts *oras.CopyGraphOptions, fetcher content.Fetcher) {}
Expand Down
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/status/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package status

import (
"io"
"sync"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -39,8 +40,7 @@ type PullHandler interface {
// TrackTarget returns a tracked target.
// If no TTY is available, it returns the original target.
TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, error)
// StopTracking stops tracking the target if available.
StopTracking()
io.Closer
// OnNodeProcessing is called when processing a manifest.
OnNodeProcessing(desc ocispec.Descriptor) error
// OnNodeDownloading is called before downloading a node.
Expand Down
6 changes: 4 additions & 2 deletions cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ func (ph *TextPullHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, e
return gt, nil
}

// StopTracking stop tracked target.
func (ph *TextPullHandler) StopTracking() {}
// Close implements io.Closer.
func (ph *TextPullHandler) Close() error {
return nil
}

// OnNodeDownloading implements PullHandler.
func (ph *TextPullHandler) OnNodeDownloading(desc ocispec.Descriptor) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/internal/display/status/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func (ph *TTYPullHandler) OnNodeSkipped(printed *sync.Map, desc ocispec.Descript
return ph.printOnce(printed, desc, "Skipped ")

Check warning on line 134 in cmd/oras/internal/display/status/tty.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/tty.go#L133-L134

Added lines #L133 - L134 were not covered by tests
}

// StopTracking stop tracked target.
func (ph *TTYPullHandler) StopTracking() {
ph.tracked.Close()
// Close implements io.Closer.
func (ph *TTYPullHandler) Close() error {
return ph.tracked.Close()

Check warning on line 139 in cmd/oras/internal/display/status/tty.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/tty.go#L138-L139

Added lines #L138 - L139 were not covered by tests
}

// TrackTarget returns a tracked target.
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget,
if err != nil {
return ocispec.Descriptor{}, false, nil, err

Check warning on line 163 in cmd/oras/root/pull.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/root/pull.go#L163

Added line #L163 was not covered by tests
}
defer statusHandler.StopTracking()
defer statusHandler.Close()
var printed sync.Map
var getConfigOnce sync.Once
var layerSkipped atomic.Bool
Expand Down

0 comments on commit 63d664b

Please sign in to comment.