From 98703b567716b4d013463974ecdc00809df70efd Mon Sep 17 00:00:00 2001 From: Jim Teeuwen Date: Fri, 26 Jul 2013 23:47:30 +0200 Subject: [PATCH] Adds a check to ensure the specified output directory actually exists. --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index cc62d90..618f461 100644 --- a/main.go +++ b/main.go @@ -124,8 +124,17 @@ func safeFilename(out, in string) string { out, _ = filepath.Abs(filepath.Clean(out)) } + // Ensure output directory exists while we're here. + stat, err := os.Lstat(out) + if err != nil { + os.MkdirAll(out, 0755) + } else if !stat.IsDir() { + fmt.Fprintf(os.Stderr, "Output path is an existing file.\n") + os.Exit(1) + } + filename := path.Join(out, in+".go") - _, err := os.Lstat(filename) + _, err = os.Lstat(filename) if err == nil { // File already exists. Pad name with a sequential number until we