@@ -18,14 +18,14 @@ package util
18
18
19
19
import (
20
20
"archive/tar"
21
- "compress/gzip"
22
21
"encoding/json"
23
22
"errors"
24
23
"io/ioutil"
25
24
"os"
26
25
"path/filepath"
27
26
"strings"
28
27
28
+ "github.com/containers/image/pkg/compression"
29
29
"github.com/containers/image/types"
30
30
"github.com/golang/glog"
31
31
)
@@ -87,13 +87,23 @@ func getFileSystemFromReference(ref types.ImageReference, imageName string) (str
87
87
for _ , b := range img .LayerInfos () {
88
88
bi , _ , err := imgSrc .GetBlob (b )
89
89
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
91
}
92
- gzf , err := gzip .NewReader (bi )
92
+ // try and detect layer compression
93
+ f , reader , err := compression .DetectCompression (bi )
93
94
if err != nil {
94
- glog .Errorf ("Failed to read layers with error: %s" , err )
95
+ glog .Errorf ("Failed to detect image compression: %s" , err )
96
+ return "" , err
95
97
}
96
- tr := tar .NewReader (gzf )
98
+ if f != nil {
99
+ // decompress if necessary
100
+ reader , err = f (reader )
101
+ if err != nil {
102
+ glog .Errorf ("Failed to decompress image: %s" , err )
103
+ return "" , err
104
+ }
105
+ }
106
+ tr := tar .NewReader (reader )
97
107
err = unpackTar (tr , path )
98
108
if err != nil {
99
109
glog .Errorf ("Failed to untar layer with error: %s" , err )
@@ -128,27 +138,8 @@ func getConfigFromReference(ref types.ImageReference, source string) (ConfigSche
128
138
func CleanupImage (image Image ) {
129
139
if image .FSPath != "" {
130
140
glog .Infof ("Removing image filesystem directory %s from system" , image .FSPath )
131
- errMsg := remove (image .FSPath , true )
132
- if errMsg != "" {
133
- glog .Error (errMsg )
141
+ if err := os .RemoveAll (image .FSPath ); err != nil {
142
+ glog .Error (err .Error ())
134
143
}
135
144
}
136
145
}
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