From dffcc99373a455e114a92b6f9d212a8ee9e4d9de Mon Sep 17 00:00:00 2001 From: Chaitanya Bankanhal Date: Sun, 23 Aug 2020 01:22:38 +0530 Subject: [PATCH] plugins: Create availablePlugins config file if it does not exist. --- fs/rc/webgui/plugins.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fs/rc/webgui/plugins.go b/fs/rc/webgui/plugins.go index 645a02830..d6b2cf117 100644 --- a/fs/rc/webgui/plugins.go +++ b/fs/rc/webgui/plugins.go @@ -7,6 +7,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "os" "path/filepath" "regexp" "strings" @@ -97,13 +98,23 @@ func (p *Plugins) readFromFile() (err error) { return err } availablePluginsJSON := filepath.Join(pluginsConfigPath, p.fileName) - data, err := ioutil.ReadFile(availablePluginsJSON) - if err != nil { - // create a file ? - } - err = json.Unmarshal(data, &p) - if err != nil { - fs.Logf(nil, "%s", err) + _, err = os.Stat(availablePluginsJSON) + if err == nil { + data, err := ioutil.ReadFile(availablePluginsJSON) + if err != nil { + return err + } + err = json.Unmarshal(data, &p) + if err != nil { + fs.Logf(nil, "%s", err) + } + return nil + } else if os.IsNotExist(err) { + // path does not exist + err = p.writeToFile() + if err != nil { + return err + } } return nil }