fix(dump): don't try to save a config file if none was provided and dump vikunja env variables

This commit is contained in:
kolaente 2022-02-19 11:32:24 +01:00
parent 44aaf0a4ec
commit 8cb92b3924
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"strings"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files" "code.vikunja.io/api/pkg/files"
@ -43,12 +44,31 @@ func Dump(filename string) error {
// Config // Config
log.Info("Start dumping config file...") log.Info("Start dumping config file...")
err = writeFileToZip(viper.ConfigFileUsed(), dumpWriter) if viper.ConfigFileUsed() != "" {
if err != nil { err = writeFileToZip(viper.ConfigFileUsed(), dumpWriter)
return fmt.Errorf("error saving config file: %s", err) if err != nil {
return fmt.Errorf("error saving config file: %s", err)
}
} else {
log.Warning("No config file found, not including one in the dump. This usually happens when environment variables are used for configuration.")
} }
log.Info("Dumped config file") log.Info("Dumped config file")
env := os.Environ()
dotEnv := ""
for _, e := range env {
if strings.Contains(e, "VIKUNJA_") {
dotEnv += e + "\n"
}
}
if dotEnv != "" {
err = utils.WriteBytesToZip(".env", []byte(dotEnv), dumpWriter)
if err != nil {
return fmt.Errorf("error saving env file: %s", err)
}
log.Info("Dumped .env file")
}
// Version // Version
log.Info("Start dumping version file...") log.Info("Start dumping version file...")
err = utils.WriteBytesToZip("VERSION", []byte(version.Version), dumpWriter) err = utils.WriteBytesToZip("VERSION", []byte(version.Version), dumpWriter)