Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ func TestGotifyConfigFile(t *testing.T) {
assert.Equal(t, "fromfile", conf.DefaultUser.Name)
}

func TestLegacyConfigFile(t *testing.T) {
mode.Set(mode.TestDev)
dir := t.TempDir()
assert.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(""), 0o600))
t.Chdir(dir)

_, logs := Get()

assert.Len(t, logs, 1)
assert.Contains(t, logs[0].Msg, "the YAML config file is no longer supported. Convert it with 'gotify-server migrate-config")
}

func TestAddSlash(t *testing.T) {
mode.Set(mode.TestDev)
os.Setenv("GOTIFY_UPLOADEDIMAGESDIR", "../data/images")
Expand Down
13 changes: 13 additions & 0 deletions config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ import (

var osStat = os.Stat

func checkLegacyConfigFiles() error {
for _, file := range []string{"config.yml", "/etc/gotify/config.yml"} {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a great idea as it will make it impossible to start the server if there happens to be a config in /etc you are not authorized to delete.

Config.yml also could be for anything. I would say this should be a warning or warning unless no environment variable that start with GOTIFY_ exists.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. I wanted a way to prevent a user from just auto-updating, therefore the hard crash. But yeah, your right, I'll just close this PR.

if _, err := osStat(file); err == nil {
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)
}
}
return nil
}

func loadFiles() []FutureLog {
if err := checkLegacyConfigFiles(); err != nil {
return []FutureLog{futureFatal(err.Error())}
}

if configFile := os.Getenv("GOTIFY_CONFIG_FILE"); configFile != "" {
log, _ := loadFile(configFile)
return []FutureLog{log}
Expand Down
Loading