fix conflict subdirectory when untardir is the clashing directory

Signed-off-by: zwwhdls <zwwhdls@hotmail.com>
pull/7187/head
zwwhdls 6 years ago
parent 7055457cfd
commit 7f4ac180e3

@ -163,7 +163,7 @@ func TestPullCmd(t *testing.T) {
if err != nil {
if tt.wantError {
if tt.wantErrorMsg != "" && tt.wantErrorMsg == err.Error() {
t.Fatalf("%q reported error not equel wantErr, reported: %s, wanted: %s", tt.name, err, tt.wantErrorMsg)
t.Fatalf("Actual error %s, not equal to expected error %s", err, tt.wantErrorMsg)
}
return
}

@ -109,13 +109,18 @@ func (p *Pull) Run(chartRef string) (string, error) {
if !filepath.IsAbs(ud) {
ud = filepath.Join(p.DestDir, ud)
}
if _, err := os.Stat(ud); err != nil {
if err := os.MkdirAll(ud, 0755); err != nil {
// Let udCheck to check conflict file/dir without replacing ud when untarDir is .
udCheck := ud
if udCheck == "." {
_, udCheck = filepath.Split(chartRef)
}
if _, err := os.Stat(udCheck); err != nil {
if err := os.MkdirAll(udCheck, 0755); err != nil {
return out.String(), errors.Wrap(err, "failed to untar (mkdir)")
}
} else if ud != "." {
return out.String(), errors.Errorf("failed to untar: a file or directory with the name %s already exists", ud)
} else {
return out.String(), errors.Errorf("failed to untar: a file or directory with the name %s already exists", udCheck)
}
return out.String(), chartutil.ExpandFile(ud, saved)

Loading…
Cancel
Save