Fixes Config.validate() to create the directory of the output
file, if it does not exist.
This commit is contained in:
parent
ca6a684780
commit
b1eab644d7
13
config.go
13
config.go
|
@ -149,10 +149,21 @@ func (c *Config) validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, err = os.Lstat(c.Output)
|
stat, err = os.Lstat(c.Output)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("Output path: %v", err)
|
return fmt.Errorf("Output path: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File does not exist. This is fine, just make
|
||||||
|
// sure the directory it is to be in exists.
|
||||||
|
dir, _ := filepath.Split(c.Output)
|
||||||
|
err = os.MkdirAll(dir, 0744)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Create output directory: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if stat != nil && stat.IsDir() {
|
if stat != nil && stat.IsDir() {
|
||||||
return fmt.Errorf("Output path is a directory.")
|
return fmt.Errorf("Output path is a directory.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user