From 65102966a1be407d78a4ca718c09fd3d521e7291 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Mon, 13 Apr 2020 18:16:44 -0400 Subject: [PATCH] add data folder on startup Instead of making users create the data folder create it for them on startup if it doesn't exist. --- config/config.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/config.go b/config/config.go index b47ebdd..c2cbe8e 100644 --- a/config/config.go +++ b/config/config.go @@ -344,6 +344,28 @@ func (c *Configuration) EnsureFilePermissions() error { r := regexp.MustCompile("^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$") + // add trailing slash on data directory is no trailing slash exists + if ! strings.HasSuffix(c.System.Data, "/") { + c.System.Data = c.System.Data + "/" + } + + // create the daemon-data dir if it doesn't exist + p, file := path.Split(c.System.Data) + + if _, err := os.Stat(c.System.Data); err != nil { + // if file doesn't exist + if os.IsNotExist(err) { + // + if _, err = os.Stat(c.System.Data); err != nil { + if file == "" { + if err = os.Mkdir(p, 0755); err != nil { + } + zap.S().Debugf("created %s folder", c.System.Data) + } + } + } + } + files, err := ioutil.ReadDir(c.System.Data) if err != nil { return err