Skip to content

Commit

Permalink
add support for symlinks in tarballs
Browse files Browse the repository at this point in the history
This PR extends the downloader to support symlinks in tarball archives.

Fixes kubernetes-sigs#359
  • Loading branch information
starpit committed Oct 29, 2019
1 parent d67e087 commit e49401d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error {
if err := os.MkdirAll(path, os.FileMode(hdr.Mode)); err != nil {
return errors.Wrap(err, "failed to create directory from tar")
}
case tar.TypeSymlink:
if err := os.Symlink(hdr.Linkname, path); err != nil {
return errors.Wrap(err, "failed to create symlink from tar")
}
case tar.TypeReg:
dir := filepath.Dir(path)
glog.V(4).Infof("tar: ensuring parent dirs exist for regular file, dir=%s", dir)
Expand Down
4 changes: 4 additions & 0 deletions pkg/download/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func Test_extractTARGZ(t *testing.T) {
in: "test-without-directory.tar.gz",
files: []string{"/foo"},
},
{
in: "test-with-symlinks.tar.gz",
files: []string{"/symlinks/", "/symlinks/message", "/symlinks/msg"},
},
{
in: "test-with-nesting-with-directory-entries.tar.gz",
files: []string{
Expand Down
Binary file added pkg/download/testdata/test-with-symlinks.tar.gz
Binary file not shown.

0 comments on commit e49401d

Please sign in to comment.