@@ -76,6 +76,8 @@ func (ta TarArchive) Decompress(destination string) error {
76
76
// metadata.
77
77
directories := map [string ]interface {}{}
78
78
79
+ // Struct and slice to collect symlinks and create them after all files have
80
+ // been created
79
81
type header struct {
80
82
name string
81
83
linkname string
@@ -166,6 +168,18 @@ func (ta TarArchive) Decompress(destination string) error {
166
168
}
167
169
}
168
170
171
+ // Sort the symlinks so that symlinks of symlinks have their base link
172
+ // created before they are created.
173
+ //
174
+ // For example:
175
+ // b-sym -> a-sym/file
176
+ // a-sym -> dir
177
+ // c-sym -> a-sym/other-file
178
+ //
179
+ // Will sort to:
180
+ // a-sym -> dir
181
+ // b-sym -> a-sym/file
182
+ // c-sym -> a-sym/other-file
169
183
sort .Slice (symlinkHeaders , func (i , j int ) bool {
170
184
return filepath .Clean (symlinkHeaders [i ].name ) < filepath .Clean (filepath .Join (filepath .Dir (symlinkHeaders [j ].name ), symlinkHeaders [j ].linkname ))
171
185
})
@@ -313,6 +327,8 @@ func NewZipArchive(inputReader io.Reader) ZipArchive {
313
327
// Decompress reads from ZipArchive and writes files into the destination
314
328
// specified.
315
329
func (z ZipArchive ) Decompress (destination string ) error {
330
+ // Struct and slice to collect symlinks and create them after all files have
331
+ // been created
316
332
type header struct {
317
333
name string
318
334
linkname string
@@ -400,6 +416,18 @@ func (z ZipArchive) Decompress(destination string) error {
400
416
}
401
417
}
402
418
419
+ // Sort the symlinks so that symlinks of symlinks have their base link
420
+ // created before they are created.
421
+ //
422
+ // For example:
423
+ // b-sym -> a-sym/file
424
+ // a-sym -> dir
425
+ // c-sym -> a-sym/other-file
426
+ //
427
+ // Will sort to:
428
+ // a-sym -> dir
429
+ // b-sym -> a-sym/file
430
+ // c-sym -> a-sym/other-file
403
431
sort .Slice (symlinkHeaders , func (i , j int ) bool {
404
432
return filepath .Clean (symlinkHeaders [i ].name ) < filepath .Clean (filepath .Join (filepath .Dir (symlinkHeaders [j ].name ), symlinkHeaders [j ].linkname ))
405
433
})
0 commit comments