@@ -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,24 @@ 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
+ return "" , err
91
92
}
92
- gzf , err := gzip .NewReader (bi )
93
+ // try and detect layer compression
94
+ f , reader , err := compression .DetectCompression (bi )
93
95
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
95
98
}
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 )
97
108
err = unpackTar (tr , path )
98
109
if err != nil {
99
110
glog .Errorf ("Failed to untar layer with error: %s" , err )
@@ -128,27 +139,8 @@ func getConfigFromReference(ref types.ImageReference, source string) (ConfigSche
128
139
func CleanupImage (image Image ) {
129
140
if image .FSPath != "" {
130
141
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 ())
134
144
}
135
145
}
136
146
}
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