Skip to content

Commit

Permalink
Make the corruption error more clear and fix zarf tools cache-clear (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 authored Oct 6, 2022
1 parent 23f39d3 commit 1a77680
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ var clearCacheCmd = &cobra.Command{
Aliases: []string{"c"},
Short: "Clears the configured git and image cache directory",
Run: func(cmd *cobra.Command, args []string) {
if err := os.RemoveAll(config.CreateOptions.CachePath); err != nil {
message.Fatalf("Unable to clear the cache driectory %s: %s", config.CreateOptions.CachePath, err.Error())
message.Debugf("Cache directory set to: %s", config.GetAbsCachePath())
if err := os.RemoveAll(config.GetAbsCachePath()); err != nil {
message.Fatalf("Unable to clear the cache driectory %s: %s", config.GetAbsCachePath(), err.Error())
}
},
}
Expand Down
8 changes: 6 additions & 2 deletions src/internal/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"path/filepath"
"strings"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/internal/message"
Expand Down Expand Up @@ -44,7 +45,7 @@ func PullAll(buildImageList []string, imageTarballPath string) map[name.Tag]v1.I
spinner.Updatef("Fetching image metadata (%d of %d): %s", idx+1, imageCount, src)
img, err := crane.Pull(src, config.GetCraneOptions()...)
if err != nil {
spinner.Fatalf(err, "Unable to pull the image %s", src)
spinner.Fatalf(err, "Unable to pull the image \"%s\"", src)
}
imageCachePath := filepath.Join(config.GetAbsCachePath(), config.ZarfImageCacheDir)
img = cache.Image(img, cache.NewFilesystemCache(imageCachePath))
Expand Down Expand Up @@ -87,8 +88,11 @@ func PullAll(buildImageList []string, imageTarballPath string) map[name.Tag]v1.I
case update.Error != nil && errors.Is(update.Error, io.EOF):
progressBar.Success("Pulling %d images (%s)", len(imageMap), utils.ByteFormat(float64(update.Total), 2))
return tagToImage
case update.Error != nil && strings.HasPrefix(update.Error.Error(), "archive/tar: missed writing "):
// Handle potential image cache corruption with a more helpful error. See L#54 in libexec/src/archive/tar/writer.go
message.Fatalf(update.Error, "potential image cache corruption: %s of %v bytes - try clearing cache with \"zarf tools clear-cache\"", update.Error.Error(), update.Total)
case update.Error != nil:
message.Fatal(update.Error, "error writing image tarball")
message.Fatalf(update.Error, "error writing image tarball: %s", update.Error.Error())
default:
title = fmt.Sprintf("Pulling %d images (%s of %s)", len(imageMap),
utils.ByteFormat(float64(update.Complete), 2),
Expand Down

0 comments on commit 1a77680

Please sign in to comment.