Adds a check to ensure the specified output directory actually exists.

pull/4/head v2.0.0
Jim Teeuwen 2013-07-26 23:47:30 +02:00
parent f0faa42c2f
commit 98703b5677
1 changed files with 10 additions and 1 deletions

11
main.go
View File

@ -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