Skip to content

Commit

Permalink
[spin] broken symlinks (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
samyfodil committed Aug 23, 2024
1 parent ac277c8 commit c66e51f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/spin/registry/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 10 additions & 4 deletions tools/spin/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/spin/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c66e51f

Please sign in to comment.