Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1469 : Remove file that matches with the directory path #1478

Merged
9 changes: 9 additions & 0 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,15 @@ func Volumes() []string {
}

func mkdirAllWithPermissions(path string, mode os.FileMode, uid, gid int64) error {
// Check if a file already exists on the path, if yes then delete it
info, err := os.Stat(path)
if !os.IsNotExist(err) && !info.IsDir() {
logrus.Tracef("removing file because it needs to be a directory %s", path)
if err := os.Remove(path); err != nil {
return errors.Wrapf(err, "error removing %s to make way for new directory.", path)
}
}

if err := os.MkdirAll(path, mode); err != nil {
return err
}
Expand Down