Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

manually detect tar compression before attempting to unpack #95

Merged
merged 2 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
deps = [
"//vendor/github.com/containers/image/docker:go_default_library",
"//vendor/github.com/containers/image/docker/tarfile:go_default_library",
"//vendor/github.com/containers/image/pkg/compression:go_default_library",
"//vendor/github.com/containers/image/types:go_default_library",
"//vendor/github.com/docker/docker/client:go_default_library",
"//vendor/github.com/docker/docker/pkg/system:go_default_library",
Expand Down
44 changes: 18 additions & 26 deletions pkg/util/image_prep_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package util

import (
"archive/tar"
"compress/gzip"
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/containers/image/pkg/compression"
"github.com/containers/image/types"
"github.com/golang/glog"
)
Expand Down Expand Up @@ -87,13 +87,24 @@ func getFileSystemFromReference(ref types.ImageReference, imageName string) (str
for _, b := range img.LayerInfos() {
bi, _, err := imgSrc.GetBlob(b)
if err != nil {
glog.Errorf("Failed to pull image layer with error: %s", err)
glog.Errorf("Failed to pull image layer: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably return here right? This will continue. I realize it was like this before, but we should clean it up while you're changing the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, don't think it makes sense to keep going here cause this totally screws up the image representation. Fixed

return "", err
}
gzf, err := gzip.NewReader(bi)
// try and detect layer compression
f, reader, err := compression.DetectCompression(bi)
if err != nil {
glog.Errorf("Failed to read layers with error: %s", err)
glog.Errorf("Failed to detect image compression: %s", err)
return "", err
}
tr := tar.NewReader(gzf)
if f != nil {
// decompress if necessary
reader, err = f(reader)
if err != nil {
glog.Errorf("Failed to decompress image: %s", err)
return "", err
}
}
tr := tar.NewReader(reader)
err = unpackTar(tr, path)
if err != nil {
glog.Errorf("Failed to untar layer with error: %s", err)
Expand Down Expand Up @@ -128,27 +139,8 @@ func getConfigFromReference(ref types.ImageReference, source string) (ConfigSche
func CleanupImage(image Image) {
if image.FSPath != "" {
glog.Infof("Removing image filesystem directory %s from system", image.FSPath)
errMsg := remove(image.FSPath, true)
if errMsg != "" {
glog.Error(errMsg)
if err := os.RemoveAll(image.FSPath); err != nil {
glog.Error(err.Error())
}
}
}

func remove(path string, dir bool) string {
var errStr string
if path == "" {
return ""
}

var err error
if dir {
err = os.RemoveAll(path)
} else {
err = os.Remove(path)
}
if err != nil {
errStr = "\nUnable to remove " + path
}
return errStr
}
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if [ ! "$(git status --porcelain)" ]; then
# Check gazelle if everything is up to date.
bazel run //:gazelle
if [ "$(git status --porcelain)" ]; then
echo "BUILD files out of date. Run `bazel run //:gazelle` to update them."
echo "BUILD files out of date. Run 'bazel run //:gazelle' to update them."
exit 1
fi
fi