fix conflict subdirectory when untardir is the clashing directory

Signed-off-by: zwwhdls <zwwhdls@hotmail.com>
pull/7188/head
zwwhdls 6 years ago
parent 908f8316ed
commit afeccac93d

@ -166,13 +166,20 @@ func (f *fetchCmd) run() error {
if !filepath.IsAbs(ud) {
ud = filepath.Join(f.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 the current directory(.).
udCheck := ud
if udCheck == "." {
_, udCheck = filepath.Split(f.chartRef)
} else {
_, chartName := filepath.Split(f.chartRef)
udCheck = filepath.Join(udCheck, chartName)
}
if _, err := os.Stat(udCheck); err != nil {
if err := os.MkdirAll(udCheck, 0755); err != nil {
return fmt.Errorf("Failed to untar (mkdir): %s", err)
}
} else {
return fmt.Errorf("failed to untar: a file or directory with the name %s already exists", ud)
return fmt.Errorf("Failed to untar: a file or directory with the name %s already exists", udCheck)
}
return chartutil.ExpandFile(ud, saved)

@ -188,7 +188,7 @@ func TestFetchCmd(t *testing.T) {
if err := cmd.RunE(cmd, []string{tt.chart}); err != nil {
if tt.fail {
if tt.wantErrorMsg != "" && strings.Contains(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
}

Loading…
Cancel
Save