From 65102966a1be407d78a4ca718c09fd3d521e7291 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Mon, 13 Apr 2020 18:16:44 -0400 Subject: [PATCH 1/4] 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 From df9c4835c41b41b4d151deca4900c345c2011031 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Tue, 14 Apr 2020 00:03:16 -0400 Subject: [PATCH 2/4] fix folder adding Sorry dane I missed that I nested those. --- config/config.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index c2cbe8e..c7714b7 100644 --- a/config/config.go +++ b/config/config.go @@ -350,19 +350,15 @@ func (c *Configuration) EnsureFilePermissions() error { } // create the daemon-data dir if it doesn't exist - p, file := path.Split(c.System.Data) + p, _ := 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) - } + if err = os.Mkdir(p, 0755); err != nil { } + zap.S().Debugf("created %s folder", c.System.Data) } } From da093e7cf7c25b33684d7bce2a931f966f2cdb12 Mon Sep 17 00:00:00 2001 From: "Michael (Parker) Parker" Date: Tue, 14 Apr 2020 13:07:10 -0400 Subject: [PATCH 3/4] Update config/config.go remove extra logging. Co-Authored-By: Lance Pioch --- config/config.go | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config.go b/config/config.go index c7714b7..659d134 100644 --- a/config/config.go +++ b/config/config.go @@ -358,7 +358,6 @@ func (c *Configuration) EnsureFilePermissions() error { // if err = os.Mkdir(p, 0755); err != nil { } - zap.S().Debugf("created %s folder", c.System.Data) } } From 9c5855663c701832726f6a59ebdf2257a84c56a9 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Tue, 14 Apr 2020 22:06:19 -0400 Subject: [PATCH 4/4] return errors Actually return errors for stat and mkdir. --- config/config.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/config.go b/config/config.go index 659d134..c4001eb 100644 --- a/config/config.go +++ b/config/config.go @@ -357,7 +357,12 @@ func (c *Configuration) EnsureFilePermissions() error { if os.IsNotExist(err) { // if err = os.Mkdir(p, 0755); err != nil { + // of we can't make the directory return error + return err } + } else { + // if the error is anything but IsNotExist + return err } }