Skip to content

Commit c1ee4f4

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

2 files changed

Lines changed: 26 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ import (
1111

1212
var osStat = os.Stat
1313

14+
func checkLegacyConfigFiles() []FutureLog {
15+
var logs []FutureLog
16+
for _, file := range []string{"config.yml", "/etc/gotify/config.yml"} {
17+
if _, err := osStat(file); err == nil {
18+
logs = append(logs, futureFatal(fmt.Sprintf("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)))
19+
}
20+
}
21+
return logs
22+
}
23+
1424
func loadFiles() []FutureLog {
25+
if logs := checkLegacyConfigFiles(); len(logs) > 0 {
26+
return logs
27+
}
28+
1529
if configFile := os.Getenv("GOTIFY_CONFIG_FILE"); configFile != "" {
1630
log, _ := loadFile(configFile)
1731
return []FutureLog{log}

0 commit comments

Comments
 (0)