@@ -18,14 +18,14 @@ package util
1818
1919import (
2020 "archive/tar"
21- "compress/gzip"
2221 "encoding/json"
2322 "errors"
2423 "io/ioutil"
2524 "os"
2625 "path/filepath"
2726 "strings"
2827
28+ "github.com/containers/image/pkg/compression"
2929 "github.com/containers/image/types"
3030 "github.com/golang/glog"
3131)
@@ -87,13 +87,24 @@ func getFileSystemFromReference(ref types.ImageReference, imageName string) (str
8787 for _ , b := range img .LayerInfos () {
8888 bi , _ , err := imgSrc .GetBlob (b )
8989 if err != nil {
90- glog .Errorf ("Failed to pull image layer with error: %s" , err )
90+ glog .Errorf ("Failed to pull image layer: %s" , err )
91+ return "" , err
9192 }
92- gzf , err := gzip .NewReader (bi )
93+ // try and detect layer compression
94+ f , reader , err := compression .DetectCompression (bi )
9395 if err != nil {
94- glog .Errorf ("Failed to read layers with error: %s" , err )
96+ glog .Errorf ("Failed to detect image compression: %s" , err )
97+ return "" , err
9598 }
96- tr := tar .NewReader (gzf )
99+ if f != nil {
100+ // decompress if necessary
101+ reader , err = f (reader )
102+ if err != nil {
103+ glog .Errorf ("Failed to decompress image: %s" , err )
104+ return "" , err
105+ }
106+ }
107+ tr := tar .NewReader (reader )
97108 err = unpackTar (tr , path )
98109 if err != nil {
99110 glog .Errorf ("Failed to untar layer with error: %s" , err )
@@ -128,27 +139,8 @@ func getConfigFromReference(ref types.ImageReference, source string) (ConfigSche
128139func CleanupImage (image Image ) {
129140 if image .FSPath != "" {
130141 glog .Infof ("Removing image filesystem directory %s from system" , image .FSPath )
131- errMsg := remove (image .FSPath , true )
132- if errMsg != "" {
133- glog .Error (errMsg )
142+ if err := os .RemoveAll (image .FSPath ); err != nil {
143+ glog .Error (err .Error ())
134144 }
135145 }
136146}
137-
138- func remove (path string , dir bool ) string {
139- var errStr string
140- if path == "" {
141- return ""
142- }
143-
144- var err error
145- if dir {
146- err = os .RemoveAll (path )
147- } else {
148- err = os .Remove (path )
149- }
150- if err != nil {
151- errStr = "\n Unable to remove " + path
152- }
153- return errStr
154- }
0 commit comments