Adds a check to ensure the specified output directory actually exists.
This commit is contained in:
parent
f0faa42c2f
commit
98703b5677
11
main.go
11
main.go
|
@ -124,8 +124,17 @@ func safeFilename(out, in string) string {
|
||||||
out, _ = filepath.Abs(filepath.Clean(out))
|
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")
|
filename := path.Join(out, in+".go")
|
||||||
_, err := os.Lstat(filename)
|
_, err = os.Lstat(filename)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// File already exists. Pad name with a sequential number until we
|
// File already exists. Pad name with a sequential number until we
|
||||||
|
|
Loading…
Reference in New Issue
Block a user