@@ -196,7 +196,6 @@ func (e *Extractor) Zip(ctx context.Context, body io.Reader, location string, re
196
196
return errors .Annotatef (err , "Read the zip file" )
197
197
}
198
198
199
- files := []file {}
200
199
links := []link {}
201
200
202
201
// We make the first pass creating the directory structure, or we could end up
@@ -239,35 +238,26 @@ func (e *Extractor) Zip(ctx context.Context, body io.Reader, location string, re
239
238
}
240
239
// We only check for symlinks because hard links aren't possible
241
240
case info .Mode ()& os .ModeSymlink != 0 :
242
- f , err := header .Open ()
243
- if err != nil {
241
+ if f , err := header .Open (); err != nil {
244
242
return errors .Annotatef (err , "Open link %s" , path )
245
- }
246
- name , err := ioutil .ReadAll (f )
247
- if err != nil {
243
+ } else if name , err := ioutil .ReadAll (f ); err != nil {
248
244
return errors .Annotatef (err , "Read address of link %s" , path )
245
+ } else {
246
+ links = append (links , link {Path : path , Name : string (name )})
247
+ f .Close ()
249
248
}
250
- links = append (links , link {Path : path , Name : string (name )})
251
249
default :
252
- f , err := header .Open ()
253
- if err != nil {
250
+ if f , err := header .Open (); err != nil {
254
251
return errors .Annotatef (err , "Open file %s" , path )
252
+ } else if err := e .copy (ctx , path , info .Mode (), f ); err != nil {
253
+ return errors .Annotatef (err , "Create file %s" , path )
254
+ } else {
255
+ f .Close ()
255
256
}
256
- var data bytes.Buffer
257
- if _ , err := copyCancel (ctx , & data , f ); err != nil {
258
- return errors .Annotatef (err , "Read contents of file %s" , path )
259
- }
260
- files = append (files , file {Path : path , Mode : info .Mode (), Data : data })
261
- }
262
- }
263
-
264
- // Now we make another pass creating the files and links
265
- for i := range files {
266
- if err := e .copy (ctx , files [i ].Path , files [i ].Mode , & files [i ].Data ); err != nil {
267
- return errors .Annotatef (err , "Create file %s" , files [i ].Path )
268
257
}
269
258
}
270
259
260
+ // Now we make another pass creating the links
271
261
for i := range links {
272
262
select {
273
263
case <- ctx .Done ():
0 commit comments