Create the root directory if it doesn't exist

The `git clone` command will create the root directory if it doesn't
exist, but if `git clone` fails, the root directory needs to be present
so that we can write the error to a file under the directory.
This commit is contained in:
Nan Yu 2021-05-11 16:59:17 -07:00
parent 1c2a18b0cb
commit 583ae46ec6
1 changed files with 7 additions and 0 deletions

View File

@ -230,6 +230,13 @@ func (l *customLogger) exportError(content string) {
// writeContent writes the error content to the error file.
func (l *customLogger) writeContent(content []byte) {
if _, err := os.Stat(*flRoot); os.IsNotExist(err) {
fileMode := os.FileMode(0755)
if err := os.Mkdir(*flRoot, fileMode); err != nil {
l.Logger.Error(err, "can't create the root directory", "root", *flRoot)
return
}
}
tmpFile, err := ioutil.TempFile(*flRoot, "tmp-err-")
if err != nil {
l.Logger.Error(err, "can't create temporary error-file", "directory", *flRoot, "prefix", "tmp-err-")