Skip to content

Commit

Permalink
Merge pull request #174 from hashicorp/revert-symlinks
Browse files Browse the repository at this point in the history
Revert "Adds support for Symlinks in all Tar decompressors"
  • Loading branch information
schmichael authored Mar 26, 2019
2 parents d9c5f68 + 509ff2e commit 69dec09
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 109 deletions.
2 changes: 0 additions & 2 deletions decompress_bzip2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func TestBzip2Decompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -22,7 +21,6 @@ func TestBzip2Decompressor(t *testing.T) {
true,
true,
nil,
nil,
"",
nil,
},
Expand Down
2 changes: 0 additions & 2 deletions decompress_gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func TestGzipDecompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -22,7 +21,6 @@ func TestGzipDecompressor(t *testing.T) {
true,
true,
nil,
nil,
"",
nil,
},
Expand Down
9 changes: 0 additions & 9 deletions decompress_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ func untar(input io.Reader, dst, src string, dir bool) error {
path = filepath.Join(path, hdr.Name)
}

if hdr.Typeflag == tar.TypeSymlink {
// If the type is a symlink we re-write it and
// continue instead of attempting to copy the contents
if err := os.Symlink(hdr.Linkname, path); err != nil {
return fmt.Errorf("failed writing symbolic link: %s", err)
}
continue
}

if hdr.FileInfo().IsDir() {
if !dir {
return fmt.Errorf("expected a single file: %s", src)
Expand Down
12 changes: 0 additions & 12 deletions decompress_tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestTar(t *testing.T) {
true,
false,
[]string{"directory/", "directory/a", "directory/b"},
nil,
"",
nil,
},
Expand All @@ -23,7 +22,6 @@ func TestTar(t *testing.T) {
true,
false,
[]string{"directory/", "directory/sub/", "directory/sub/a", "directory/sub/b"},
nil,
"",
nil,
},
Expand All @@ -32,16 +30,6 @@ func TestTar(t *testing.T) {
true,
false,
[]string{"directory/", "directory/sub/", "directory/sub/a", "directory/sub/b"},
nil,
"",
&mtime,
},
{
"with-symlinks.tar",
true,
false,
[]string{"baz", "foo"},
map[string]string{"bar": "baz"},
"",
&mtime,
},
Expand Down
6 changes: 0 additions & 6 deletions decompress_tbz2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -24,7 +23,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -34,7 +32,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
true,
false,
[]string{"file"},
nil,
"",
nil,
},
Expand All @@ -44,7 +41,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
true,
false,
[]string{"file1", "file2"},
nil,
"",
nil,
},
Expand All @@ -54,7 +50,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -65,7 +60,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
true,
false,
orderingPaths,
nil,
"",
nil,
},
Expand Down
65 changes: 13 additions & 52 deletions decompress_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import (

// TestDecompressCase is a single test case for testing decompressors
type TestDecompressCase struct {
Input string // Input is the complete path to the input file
Dir bool // Dir is whether or not we're testing directory mode
Err bool // Err is whether we expect an error or not
DirList []string // DirList is the list of files for Dir mode
Symlinks map[string]string // Optional map of symlinks to test
FileMD5 string // FileMD5 is the expected MD5 for a single file
Mtime *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
Input string // Input is the complete path to the input file
Dir bool // Dir is whether or not we're testing directory mode
Err bool // Err is whether we expect an error or not
DirList []string // DirList is the list of files for Dir mode
FileMD5 string // FileMD5 is the expected MD5 for a single file
Mtime *time.Time // Mtime is the optionally expected mtime for a single file (or all files if in Dir mode)
}

// TestDecompressor is a helper function for testing generic decompressors.
Expand Down Expand Up @@ -98,17 +97,11 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {

// Directory, check for the correct contents
actual := testListDir(t, dst)
if !reflect.DeepEqual(actual.files, expected) {
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual.files, expected)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual, expected)
}

// Symlinks, check that symlinks match
if tc.Symlinks != nil && !reflect.DeepEqual(actual.symlinks, tc.Symlinks) {
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual.symlinks, tc.Symlinks)
}

// Check for correct atime/mtime
for _, dir := range actual.files {
for _, dir := range actual {
path := filepath.Join(dst, dir)
if tc.Mtime != nil {
fi, err := os.Stat(path)
Expand All @@ -131,32 +124,8 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
}
}

type testResult struct {
files []string
symlinks map[string]string
}

func (tr *testResult) AddFile(name string) {
tr.files = append(tr.files, name)
}

func (tr *testResult) AddSymlink(name, link string) {
tr.symlinks[name] = link
}

func (tr *testResult) SortFiles() {
sort.Strings(tr.files)
}

func newTestResult() *testResult {
return &testResult{
files: make([]string, 0),
symlinks: make(map[string]string),
}
}

func testListDir(t testing.T, path string) *testResult {
result := newTestResult()
func testListDir(t testing.T, path string) []string {
var result []string
err := filepath.Walk(path, func(sub string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand All @@ -171,24 +140,16 @@ func testListDir(t testing.T, path string) *testResult {
// If it is a dir, add trailing sep
if info.IsDir() {
sub += string(os.PathSeparator)
result.AddFile(sub)
} else if info.Mode()&os.ModeSymlink != 0 {
link, err := os.Readlink(filepath.Join(path, info.Name()))
if err != nil {
return err
}
result.AddSymlink(sub, link)
} else {
result.AddFile(sub)
}

result = append(result, sub)
return nil
})
if err != nil {
t.Fatalf("err: %s", err)
}

result.SortFiles()
sort.Strings(result)
return result
}

Expand Down
8 changes: 0 additions & 8 deletions decompress_tgz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestTarGzipDecompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -26,7 +25,6 @@ func TestTarGzipDecompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -36,7 +34,6 @@ func TestTarGzipDecompressor(t *testing.T) {
true,
false,
[]string{"file"},
nil,
"",
nil,
},
Expand All @@ -46,7 +43,6 @@ func TestTarGzipDecompressor(t *testing.T) {
true,
false,
[]string{"file1", "file2"},
nil,
"",
nil,
},
Expand All @@ -56,7 +52,6 @@ func TestTarGzipDecompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -66,7 +61,6 @@ func TestTarGzipDecompressor(t *testing.T) {
true,
false,
multiplePaths,
nil,
"",
nil,
},
Expand All @@ -77,7 +71,6 @@ func TestTarGzipDecompressor(t *testing.T) {
true,
false,
orderingPaths,
nil,
"",
nil,
},
Expand All @@ -89,7 +82,6 @@ func TestTarGzipDecompressor(t *testing.T) {
true,
true,
nil,
nil,
"",
nil,
},
Expand Down
7 changes: 0 additions & 7 deletions decompress_txz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestTarXzDecompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -26,7 +25,6 @@ func TestTarXzDecompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -36,7 +34,6 @@ func TestTarXzDecompressor(t *testing.T) {
true,
false,
[]string{"file"},
nil,
"",
nil,
},
Expand All @@ -46,7 +43,6 @@ func TestTarXzDecompressor(t *testing.T) {
true,
false,
[]string{"file1", "file2"},
nil,
"",
nil,
},
Expand All @@ -56,7 +52,6 @@ func TestTarXzDecompressor(t *testing.T) {
false,
true,
nil,
nil,
"",
nil,
},
Expand All @@ -66,7 +61,6 @@ func TestTarXzDecompressor(t *testing.T) {
true,
false,
multiplePaths,
nil,
"",
nil,
},
Expand All @@ -77,7 +71,6 @@ func TestTarXzDecompressor(t *testing.T) {
true,
false,
orderingPaths,
nil,
"",
nil,
},
Expand Down
2 changes: 0 additions & 2 deletions decompress_xz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func TestXzDecompressor(t *testing.T) {
false,
false,
nil,
nil,
"d3b07384d113edec49eaa6238ad5ff00",
nil,
},
Expand All @@ -22,7 +21,6 @@ func TestXzDecompressor(t *testing.T) {
true,
true,
nil,
nil,
"",
nil,
},
Expand Down
Loading

0 comments on commit 69dec09

Please sign in to comment.