diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 3576a3977..90972e0ed 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -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 }