Skip to content

Commit 69dec09

Browse files
authored
Merge pull request #174 from hashicorp/revert-symlinks
Revert "Adds support for Symlinks in all Tar decompressors"
2 parents d9c5f68 + 509ff2e commit 69dec09

11 files changed

+13
-109
lines changed

Diff for: decompress_bzip2_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func TestBzip2Decompressor(t *testing.T) {
1212
false,
1313
false,
1414
nil,
15-
nil,
1615
"d3b07384d113edec49eaa6238ad5ff00",
1716
nil,
1817
},
@@ -22,7 +21,6 @@ func TestBzip2Decompressor(t *testing.T) {
2221
true,
2322
true,
2423
nil,
25-
nil,
2624
"",
2725
nil,
2826
},

Diff for: decompress_gzip_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func TestGzipDecompressor(t *testing.T) {
1212
false,
1313
false,
1414
nil,
15-
nil,
1615
"d3b07384d113edec49eaa6238ad5ff00",
1716
nil,
1817
},
@@ -22,7 +21,6 @@ func TestGzipDecompressor(t *testing.T) {
2221
true,
2322
true,
2423
nil,
25-
nil,
2624
"",
2725
nil,
2826
},

Diff for: decompress_tar.go

-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ func untar(input io.Reader, dst, src string, dir bool) error {
4545
path = filepath.Join(path, hdr.Name)
4646
}
4747

48-
if hdr.Typeflag == tar.TypeSymlink {
49-
// If the type is a symlink we re-write it and
50-
// continue instead of attempting to copy the contents
51-
if err := os.Symlink(hdr.Linkname, path); err != nil {
52-
return fmt.Errorf("failed writing symbolic link: %s", err)
53-
}
54-
continue
55-
}
56-
5748
if hdr.FileInfo().IsDir() {
5849
if !dir {
5950
return fmt.Errorf("expected a single file: %s", src)

Diff for: decompress_tar_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func TestTar(t *testing.T) {
1414
true,
1515
false,
1616
[]string{"directory/", "directory/a", "directory/b"},
17-
nil,
1817
"",
1918
nil,
2019
},
@@ -23,7 +22,6 @@ func TestTar(t *testing.T) {
2322
true,
2423
false,
2524
[]string{"directory/", "directory/sub/", "directory/sub/a", "directory/sub/b"},
26-
nil,
2725
"",
2826
nil,
2927
},
@@ -32,16 +30,6 @@ func TestTar(t *testing.T) {
3230
true,
3331
false,
3432
[]string{"directory/", "directory/sub/", "directory/sub/a", "directory/sub/b"},
35-
nil,
36-
"",
37-
&mtime,
38-
},
39-
{
40-
"with-symlinks.tar",
41-
true,
42-
false,
43-
[]string{"baz", "foo"},
44-
map[string]string{"bar": "baz"},
4533
"",
4634
&mtime,
4735
},

Diff for: decompress_tbz2_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
1414
false,
1515
true,
1616
nil,
17-
nil,
1817
"",
1918
nil,
2019
},
@@ -24,7 +23,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
2423
false,
2524
false,
2625
nil,
27-
nil,
2826
"d3b07384d113edec49eaa6238ad5ff00",
2927
nil,
3028
},
@@ -34,7 +32,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
3432
true,
3533
false,
3634
[]string{"file"},
37-
nil,
3835
"",
3936
nil,
4037
},
@@ -44,7 +41,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
4441
true,
4542
false,
4643
[]string{"file1", "file2"},
47-
nil,
4844
"",
4945
nil,
5046
},
@@ -54,7 +50,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
5450
false,
5551
true,
5652
nil,
57-
nil,
5853
"",
5954
nil,
6055
},
@@ -65,7 +60,6 @@ func TestTarBzip2Decompressor(t *testing.T) {
6560
true,
6661
false,
6762
orderingPaths,
68-
nil,
6963
"",
7064
nil,
7165
},

Diff for: decompress_testing.go

+13-52
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import (
1818

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

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

9998
// Directory, check for the correct contents
10099
actual := testListDir(t, dst)
101-
if !reflect.DeepEqual(actual.files, expected) {
102-
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual.files, expected)
100+
if !reflect.DeepEqual(actual, expected) {
101+
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual, expected)
103102
}
104-
105-
// Symlinks, check that symlinks match
106-
if tc.Symlinks != nil && !reflect.DeepEqual(actual.symlinks, tc.Symlinks) {
107-
t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual.symlinks, tc.Symlinks)
108-
}
109-
110103
// Check for correct atime/mtime
111-
for _, dir := range actual.files {
104+
for _, dir := range actual {
112105
path := filepath.Join(dst, dir)
113106
if tc.Mtime != nil {
114107
fi, err := os.Stat(path)
@@ -131,32 +124,8 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
131124
}
132125
}
133126

134-
type testResult struct {
135-
files []string
136-
symlinks map[string]string
137-
}
138-
139-
func (tr *testResult) AddFile(name string) {
140-
tr.files = append(tr.files, name)
141-
}
142-
143-
func (tr *testResult) AddSymlink(name, link string) {
144-
tr.symlinks[name] = link
145-
}
146-
147-
func (tr *testResult) SortFiles() {
148-
sort.Strings(tr.files)
149-
}
150-
151-
func newTestResult() *testResult {
152-
return &testResult{
153-
files: make([]string, 0),
154-
symlinks: make(map[string]string),
155-
}
156-
}
157-
158-
func testListDir(t testing.T, path string) *testResult {
159-
result := newTestResult()
127+
func testListDir(t testing.T, path string) []string {
128+
var result []string
160129
err := filepath.Walk(path, func(sub string, info os.FileInfo, err error) error {
161130
if err != nil {
162131
return err
@@ -171,24 +140,16 @@ func testListDir(t testing.T, path string) *testResult {
171140
// If it is a dir, add trailing sep
172141
if info.IsDir() {
173142
sub += string(os.PathSeparator)
174-
result.AddFile(sub)
175-
} else if info.Mode()&os.ModeSymlink != 0 {
176-
link, err := os.Readlink(filepath.Join(path, info.Name()))
177-
if err != nil {
178-
return err
179-
}
180-
result.AddSymlink(sub, link)
181-
} else {
182-
result.AddFile(sub)
183143
}
184144

145+
result = append(result, sub)
185146
return nil
186147
})
187148
if err != nil {
188149
t.Fatalf("err: %s", err)
189150
}
190151

191-
result.SortFiles()
152+
sort.Strings(result)
192153
return result
193154
}
194155

Diff for: decompress_tgz_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func TestTarGzipDecompressor(t *testing.T) {
1616
false,
1717
true,
1818
nil,
19-
nil,
2019
"",
2120
nil,
2221
},
@@ -26,7 +25,6 @@ func TestTarGzipDecompressor(t *testing.T) {
2625
false,
2726
false,
2827
nil,
29-
nil,
3028
"d3b07384d113edec49eaa6238ad5ff00",
3129
nil,
3230
},
@@ -36,7 +34,6 @@ func TestTarGzipDecompressor(t *testing.T) {
3634
true,
3735
false,
3836
[]string{"file"},
39-
nil,
4037
"",
4138
nil,
4239
},
@@ -46,7 +43,6 @@ func TestTarGzipDecompressor(t *testing.T) {
4643
true,
4744
false,
4845
[]string{"file1", "file2"},
49-
nil,
5046
"",
5147
nil,
5248
},
@@ -56,7 +52,6 @@ func TestTarGzipDecompressor(t *testing.T) {
5652
false,
5753
true,
5854
nil,
59-
nil,
6055
"",
6156
nil,
6257
},
@@ -66,7 +61,6 @@ func TestTarGzipDecompressor(t *testing.T) {
6661
true,
6762
false,
6863
multiplePaths,
69-
nil,
7064
"",
7165
nil,
7266
},
@@ -77,7 +71,6 @@ func TestTarGzipDecompressor(t *testing.T) {
7771
true,
7872
false,
7973
orderingPaths,
80-
nil,
8174
"",
8275
nil,
8376
},
@@ -89,7 +82,6 @@ func TestTarGzipDecompressor(t *testing.T) {
8982
true,
9083
true,
9184
nil,
92-
nil,
9385
"",
9486
nil,
9587
},

Diff for: decompress_txz_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func TestTarXzDecompressor(t *testing.T) {
1616
false,
1717
true,
1818
nil,
19-
nil,
2019
"",
2120
nil,
2221
},
@@ -26,7 +25,6 @@ func TestTarXzDecompressor(t *testing.T) {
2625
false,
2726
false,
2827
nil,
29-
nil,
3028
"d3b07384d113edec49eaa6238ad5ff00",
3129
nil,
3230
},
@@ -36,7 +34,6 @@ func TestTarXzDecompressor(t *testing.T) {
3634
true,
3735
false,
3836
[]string{"file"},
39-
nil,
4037
"",
4138
nil,
4239
},
@@ -46,7 +43,6 @@ func TestTarXzDecompressor(t *testing.T) {
4643
true,
4744
false,
4845
[]string{"file1", "file2"},
49-
nil,
5046
"",
5147
nil,
5248
},
@@ -56,7 +52,6 @@ func TestTarXzDecompressor(t *testing.T) {
5652
false,
5753
true,
5854
nil,
59-
nil,
6055
"",
6156
nil,
6257
},
@@ -66,7 +61,6 @@ func TestTarXzDecompressor(t *testing.T) {
6661
true,
6762
false,
6863
multiplePaths,
69-
nil,
7064
"",
7165
nil,
7266
},
@@ -77,7 +71,6 @@ func TestTarXzDecompressor(t *testing.T) {
7771
true,
7872
false,
7973
orderingPaths,
80-
nil,
8174
"",
8275
nil,
8376
},

Diff for: decompress_xz_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func TestXzDecompressor(t *testing.T) {
1212
false,
1313
false,
1414
nil,
15-
nil,
1615
"d3b07384d113edec49eaa6238ad5ff00",
1716
nil,
1817
},
@@ -22,7 +21,6 @@ func TestXzDecompressor(t *testing.T) {
2221
true,
2322
true,
2423
nil,
25-
nil,
2624
"",
2725
nil,
2826
},

0 commit comments

Comments
 (0)