From 583ae46ec67c2c9c106312598dad073ad3a7b3a8 Mon Sep 17 00:00:00 2001 From: Nan Yu Date: Tue, 11 May 2021 16:59:17 -0700 Subject: [PATCH] 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. --- cmd/git-sync/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index bfd0eae..59bef74 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -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-")