From c66e51f04d774e34afa5f3b0fd0e297ccdc92baf Mon Sep 17 00:00:00 2001 From: Samy Fodil <76626119+samyfodil@users.noreply.github.com> Date: Fri, 23 Aug 2024 12:27:16 -0500 Subject: [PATCH] [spin] broken symlinks (#244) --- pkg/spin/registry/pull.go | 2 +- tools/spin/pull.go | 14 ++++++++++---- tools/spin/run.go | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/spin/registry/pull.go b/pkg/spin/registry/pull.go index ea0a059..cd59805 100644 --- a/pkg/spin/registry/pull.go +++ b/pkg/spin/registry/pull.go @@ -577,7 +577,7 @@ func tarIt(ctx context.Context, rootfsDir, outputTarball string) error { default: linkname, _ := os.Readlink(file) - header, err := tar.FileInfoHeader(fi, filepath.Clean("/"+linkname)) + header, err := tar.FileInfoHeader(fi, filepath.Clean(linkname)) if err != nil { return fmt.Errorf("failed to create tar header: %w", err) } diff --git a/tools/spin/pull.go b/tools/spin/pull.go index 369fc6f..e98d085 100644 --- a/tools/spin/pull.go +++ b/tools/spin/pull.go @@ -32,7 +32,7 @@ var pullCommand = &cli.Command{ pbar := mpb.New(mpb.WithWidth(60), mpb.WithRefreshRate(100*time.Millisecond), mpb.WithOutput(os.Stderr)) pullChan := make(chan error, 1) - pull(ctx.Context, reg, image, pbar, pullChan) + pull(ctx.Context, reg, image, pbar, pullChan, false) err = <-pullChan if err != nil { @@ -45,16 +45,22 @@ var pullCommand = &cli.Command{ }, } -func pull(ctx context.Context, reg spin.Registry, image string, pbar *mpb.Progress, pullChan chan<- error) { +func pull(ctx context.Context, reg spin.Registry, image string, pbar *mpb.Progress, pullChan chan<- error, remove bool) { progress := make(chan spin.PullProgress, 1024) var pullErr error go func() { - pullBar, _ := pbar.Add(100, - mpb.BarStyle().Build(), + opts := []mpb.BarOption{ mpb.AppendDecorators(decor.Percentage()), mpb.PrependDecorators( decor.Name("Pulling "), ), + } + if remove { + opts = append(opts, mpb.BarRemoveOnComplete()) + } + pullBar, _ := pbar.Add(100, + mpb.BarStyle().Build(), + opts..., ) for pr := range progress { if pr.Error() != io.EOF { diff --git a/tools/spin/run.go b/tools/spin/run.go index a216646..cea0f59 100644 --- a/tools/spin/run.go +++ b/tools/spin/run.go @@ -149,7 +149,7 @@ var runCommand = &cli.Command{ } containerOpts = append(containerOpts, Image(image), Command(ctx.Args().Slice()[1:]...)) // start pulling - pull(cCtx, reg, image, pbar, pullChan) + pull(cCtx, reg, image, pbar, pullChan, true) } else { containerOpts = append(containerOpts, Command(ctx.Args().Slice()...)) pullChan <- nil