fix(dump): don't try to save a config file if none was provided and dump vikunja env variables
This commit is contained in:
parent
44aaf0a4ec
commit
8cb92b3924
1 changed files with 23 additions and 3 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue