mark2web/pkg/helper/dir.go

28 lines
709 B
Go
Raw Normal View History

2019-02-28 10:43:30 +01:00
package helper
2019-03-18 13:34:52 +01:00
import (
"os"
2019-03-25 09:28:58 +01:00
"gitbase.de/apairon/mark2web/pkg/logger"
2019-03-18 13:34:52 +01:00
)
2019-02-28 10:43:30 +01:00
// CreateDirectory creates direcory with all missing parents and panic if error
func CreateDirectory(dir string) {
2019-03-29 15:49:25 +01:00
logger.D("trying to create output directory: %s", dir)
2019-02-28 10:43:30 +01:00
if dirH, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0755)
2019-03-29 15:49:25 +01:00
logger.Eexit(err, "could not create output directory '%s'", dir)
logger.I("created output directory: %s", dir)
2019-02-28 10:43:30 +01:00
} else if dirH != nil {
if dirH.IsDir() {
2019-03-29 15:49:25 +01:00
logger.I("output directory '%s' already exists", dir)
2019-02-28 10:43:30 +01:00
} else {
2019-03-29 15:49:25 +01:00
logger.Exit("output directory '%s' is no directory", dir)
2019-02-28 10:43:30 +01:00
}
} else {
2019-03-29 15:49:25 +01:00
logger.Perr(err, "unknown error for output directory '%s'", dir)
2019-02-28 10:43:30 +01:00
}
}