Skip to content

Commit

Permalink
resolve comment
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Oct 7, 2023
1 parent 243dc37 commit 5f5a1d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/oras/internal/display/progress/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newStatus() *status {
}

// NewStatus generates a status.
func NewStatus(prompt string, descriptor ocispec.Descriptor, offset uint64) *status {
func NewStatus(prompt string, descriptor ocispec.Descriptor, offset int64) *status {
return &status{
prompt: prompt,
descriptor: descriptor,
Expand Down
13 changes: 6 additions & 7 deletions cmd/oras/internal/display/track/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package track
import (
"io"
"os"
"sync/atomic"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/progress"
)

type reader struct {
base io.Reader
offset atomic.Uint64
offset int64
actionPrompt string
donePrompt string
descriptor ocispec.Descriptor
Expand Down Expand Up @@ -66,7 +65,7 @@ func (r *reader) StopManager() error {

// Stop stops the status channel without closing the manager.
func (r *reader) Stop() {
r.status <- progress.NewStatus(r.donePrompt, r.descriptor, uint64(r.descriptor.Size))
r.status <- progress.NewStatus(r.donePrompt, r.descriptor, r.descriptor.Size)
r.status <- progress.EndTiming()
close(r.status)
}
Expand All @@ -83,17 +82,17 @@ func (r *reader) Read(p []byte) (int, error) {
return n, err
}

offset := r.offset.Add(uint64(n))
r.offset = r.offset + int64(n)
if err == io.EOF {
if offset != uint64(r.descriptor.Size) {
if r.offset != r.descriptor.Size {
return n, io.ErrUnexpectedEOF
}
r.status <- progress.NewStatus(r.actionPrompt, r.descriptor, offset)
r.status <- progress.NewStatus(r.actionPrompt, r.descriptor, r.offset)
}

if len(r.status) < progress.BufferSize {
// intermediate progress might be ignored if buffer is full
r.status <- progress.NewStatus(r.actionPrompt, r.descriptor, offset)
r.status <- progress.NewStatus(r.actionPrompt, r.descriptor, r.offset)
}
return n, err
}

0 comments on commit 5f5a1d9

Please sign in to comment.