Skip to content

Commit f06f962

Browse files
committed
fix: error when legacy config exists
1 parent 9f7dc63 commit f06f962

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

config/config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ func TestGotifyConfigFile(t *testing.T) {
7474
assert.Equal(t, "fromfile", conf.DefaultUser.Name)
7575
}
7676

77+
func TestLegacyConfigFile(t *testing.T) {
78+
mode.Set(mode.TestDev)
79+
dir := t.TempDir()
80+
assert.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(""), 0o600))
81+
t.Chdir(dir)
82+
83+
_, logs := Get()
84+
85+
assert.Len(t, logs, 1)
86+
assert.Contains(t, logs[0].Msg, "the YAML config file is no longer supported. Convert it with 'gotify-server migrate-config")
87+
}
88+
7789
func TestAddSlash(t *testing.T) {
7890
mode.Set(mode.TestDev)
7991
os.Setenv("GOTIFY_UPLOADEDIMAGESDIR", "../data/images")

config/file.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ import (
1111

1212
var osStat = os.Stat
1313

14+
func checkLegacyConfigFiles() error {
15+
for _, file := range []string{"config.yml", "/etc/gotify/config.yml"} {
16+
if _, err := osStat(file); err == nil {
17+
return fmt.Errorf("found %s, the YAML config file is no longer supported. Convert it with 'gotify-server migrate-config %s', see https://gotify.net/docs/migrate-to-3", file, file)
18+
}
19+
}
20+
return nil
21+
}
22+
1423
func loadFiles() []FutureLog {
24+
if err := checkLegacyConfigFiles(); err != nil {
25+
return []FutureLog{futureFatal(err.Error())}
26+
}
27+
1528
if configFile := os.Getenv("GOTIFY_CONFIG_FILE"); configFile != "" {
1629
log, _ := loadFile(configFile)
1730
return []FutureLog{log}

0 commit comments

Comments
 (0)