fix: dont overwrite generated catalogue
continuous-integration/drone/push Build is passing Details

Closes coop-cloud/organising#190.
This commit is contained in:
decentral1se 2021-10-11 01:06:51 +02:00
parent 0140f96ca1
commit b68547b2c2
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 21 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"coopcloud.tech/abra/cli/formatter"
@ -143,8 +144,26 @@ var catalogueGenerateCommand = &cli.Command{
logrus.Fatal(err)
}
if err := ioutil.WriteFile(config.APPS_JSON, recipesJSON, 0644); err != nil {
logrus.Fatal(err)
if _, err := os.Stat(config.APPS_JSON); err != nil && os.IsNotExist(err) {
if err := ioutil.WriteFile(config.APPS_JSON, recipesJSON, 0644); err != nil {
logrus.Fatal(err)
}
} else {
if recipeName != "" {
catlFS, err := catalogue.ReadRecipeCatalogue()
if err != nil {
logrus.Fatal(err)
}
catlFS[recipeName] = catl[recipeName]
updatedRecipesJSON, err := json.MarshalIndent(catlFS, "", " ")
if err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(config.APPS_JSON, updatedRecipesJSON, 0644); err != nil {
logrus.Fatal(err)
}
}
}
logrus.Infof("generated new recipe catalogue in '%s'", config.APPS_JSON)