Skip to content

Commit 419ad73

Browse files
committed
ctr/commands/contents: expose ShowProgress
Expected to be used by nerdctl Signed-off-by: Akihiro Suda <[email protected]>
1 parent 7b0149a commit 419ad73

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

cmd/ctr/commands/content/fetch.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,22 @@ func NewFetchConfig(ctx context.Context, clicontext *cli.Context) (*FetchConfig,
146146

147147
// Fetch loads all resources into the content store and returns the image
148148
func Fetch(ctx context.Context, client *containerd.Client, ref string, config *FetchConfig) (images.Image, error) {
149-
ongoing := newJobs(ref)
149+
ongoing := NewJobs(ref)
150150

151151
pctx, stopProgress := context.WithCancel(ctx)
152152
progress := make(chan struct{})
153153

154154
go func() {
155155
if config.ProgressOutput != nil {
156156
// no progress bar, because it hides some debug logs
157-
showProgress(pctx, ongoing, client.ContentStore(), config.ProgressOutput)
157+
ShowProgress(pctx, ongoing, client.ContentStore(), config.ProgressOutput)
158158
}
159159
close(progress)
160160
}()
161161

162162
h := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
163163
if desc.MediaType != images.MediaTypeDockerSchema1Manifest {
164-
ongoing.add(desc)
164+
ongoing.Add(desc)
165165
}
166166
return nil, nil
167167
})
@@ -198,7 +198,7 @@ func Fetch(ctx context.Context, client *containerd.Client, ref string, config *F
198198
return img, nil
199199
}
200200

201-
func showProgress(ctx context.Context, ongoing *jobs, cs content.Store, out io.Writer) {
201+
func ShowProgress(ctx context.Context, ongoing *Jobs, cs content.Store, out io.Writer) {
202202
var (
203203
ticker = time.NewTicker(100 * time.Millisecond)
204204
fw = progress.NewWriter(out)
@@ -217,7 +217,7 @@ outer:
217217
tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0)
218218

219219
resolved := "resolved"
220-
if !ongoing.isResolved() {
220+
if !ongoing.IsResolved() {
221221
resolved = "resolving"
222222
}
223223
statuses[ongoing.name] = StatusInfo{
@@ -248,7 +248,7 @@ outer:
248248
}
249249

250250
// now, update the items in jobs that are not in active
251-
for _, j := range ongoing.jobs() {
251+
for _, j := range ongoing.Jobs() {
252252
key := remotes.MakeRefKey(ctx, j)
253253
keys = append(keys, key)
254254
if _, ok := activeSeen[key]; ok {
@@ -315,27 +315,27 @@ outer:
315315
}
316316
}
317317

318-
// jobs provides a way of identifying the download keys for a particular task
318+
// Jobs provides a way of identifying the download keys for a particular task
319319
// encountering during the pull walk.
320320
//
321321
// This is very minimal and will probably be replaced with something more
322322
// featured.
323-
type jobs struct {
323+
type Jobs struct {
324324
name string
325325
added map[digest.Digest]struct{}
326326
descs []ocispec.Descriptor
327327
mu sync.Mutex
328328
resolved bool
329329
}
330330

331-
func newJobs(name string) *jobs {
332-
return &jobs{
331+
func NewJobs(name string) *Jobs {
332+
return &Jobs{
333333
name: name,
334334
added: map[digest.Digest]struct{}{},
335335
}
336336
}
337337

338-
func (j *jobs) add(desc ocispec.Descriptor) {
338+
func (j *Jobs) Add(desc ocispec.Descriptor) {
339339
j.mu.Lock()
340340
defer j.mu.Unlock()
341341
j.resolved = true
@@ -347,15 +347,15 @@ func (j *jobs) add(desc ocispec.Descriptor) {
347347
j.added[desc.Digest] = struct{}{}
348348
}
349349

350-
func (j *jobs) jobs() []ocispec.Descriptor {
350+
func (j *Jobs) Jobs() []ocispec.Descriptor {
351351
j.mu.Lock()
352352
defer j.mu.Unlock()
353353

354354
var descs []ocispec.Descriptor
355355
return append(descs, j.descs...)
356356
}
357357

358-
func (j *jobs) isResolved() bool {
358+
func (j *Jobs) IsResolved() bool {
359359
j.mu.Lock()
360360
defer j.mu.Unlock()
361361
return j.resolved

0 commit comments

Comments
 (0)