Skip to content

Commit

Permalink
bugfix: Make sure that the target file has been decompressed when rec…
Browse files Browse the repository at this point in the history
…onfiguring soft link.
  • Loading branch information
aooohan committed Feb 22, 2024
1 parent c2d2206 commit 2d75a9b
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions internal/util/decompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Decompressor interface {
Decompress(dest string) error
}

type symlink struct {
oldname, newname string
}

type GzipTarDecompressor struct {
src string
}
Expand All @@ -48,11 +52,13 @@ func (g *GzipTarDecompressor) Decompress(dest string) error {
defer gzr.Close()

tr := tar.NewReader(gzr)
var symlinks []symlink
loop:
for {
header, err := tr.Next()
switch {
case err == io.EOF:
return nil
break loop
case err != nil:
return err
case header == nil:
Expand Down Expand Up @@ -88,13 +94,15 @@ func (g *GzipTarDecompressor) Decompress(dest string) error {

f.Close()
case tar.TypeSymlink:
err := os.Symlink(header.Linkname, target)
if err != nil {
return err
}

symlinks = append(symlinks, symlink{header.Linkname, target})
}
}
for _, s := range symlinks {
if err = os.Symlink(s.oldname, s.newname); err != nil {
return err
}
}
return nil
}

type XZTarDecompressor struct {
Expand All @@ -113,11 +121,13 @@ func (g *XZTarDecompressor) Decompress(dest string) error {
}

tr := tar.NewReader(gzr)
var symlinks []symlink
loop:
for {
header, err := tr.Next()
switch {
case err == io.EOF:
return nil
break loop
case err != nil:
return err
case header == nil:
Expand Down Expand Up @@ -153,13 +163,15 @@ func (g *XZTarDecompressor) Decompress(dest string) error {

f.Close()
case tar.TypeSymlink:
err := os.Symlink(header.Linkname, target)
if err != nil {
return err
}

symlinks = append(symlinks, symlink{header.Linkname, target})
}
}
for _, s := range symlinks {
if err = os.Symlink(s.oldname, s.newname); err != nil {
return err
}
}
return nil
}

type ZipDecompressor struct {
Expand Down

0 comments on commit 2d75a9b

Please sign in to comment.