diff --git a/CHANGELOG.md b/CHANGELOG.md index 8437aac..3bc92a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [v0.5.5] - 2022-04-09 + +- Fix a bug which would erase configuration when migrating from v1 to v2 config + ## [v0.5.4] - 2022-04-07 - Check the chosen command exists when configuring a profile diff --git a/config/config.go b/config/config.go index 31810cc..0b84163 100644 --- a/config/config.go +++ b/config/config.go @@ -224,6 +224,8 @@ func (cs *ConfigService) LoadConfig() error { return fmt.Errorf("Could not read config '%s': %v", path, err) } c := Config{} + cs.Config = &c + err = yaml.Unmarshal(b, &c) if err != nil { return fmt.Errorf("Could not parse YAML config '%s': %v", path, err) @@ -243,8 +245,6 @@ func (cs *ConfigService) LoadConfig() error { cs.WriteConfig() } - cs.Config = &c - return nil } diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..e9e0ca0 --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,57 @@ +package config + +import ( + "os" + "testing" +) + +func TestMigrationV1toV2(t *testing.T) { + v2Config := `config_version: 1 +server: + port: 6123 + address: http://localhost:6123 + download_path: ./ +ui: + popup_width: 500 + popup_height: 500 +profiles: +- name: standard video + command: youtube-dl + args: + - --newline + - --write-info-json + - -f + - bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best +- name: standard mp3 + command: youtube-dl + args: + - --newline + - --write-info-json + - --extract-audio + - --audio-format + - mp3 +` + cs := configServiceFromString(v2Config) + err := cs.LoadConfig() + if err != nil { + t.Errorf("got error when loading config: %s", err) + } + if cs.Config.ConfigVersion != 2 { + t.Errorf("did not migrate version (it is '%d')", cs.Config.ConfigVersion) + } + if cs.Config.Server.MaximumActiveDownloads != 2 { + t.Error("did not add MaximumActiveDownloads") + } + t.Log(cs.ConfigPath) +} + +func configServiceFromString(configString string) *ConfigService { + tmpFile, _ := os.CreateTemp("", "gropple_test_*.yml") + tmpFile.Write([]byte(configString)) + tmpFile.Close() + cs := ConfigService{ + Config: &Config{}, + ConfigPath: tmpFile.Name(), + } + return &cs +} diff --git a/main.go b/main.go index 32316ee..53414bd 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ var downloads download.Downloads var downloadId = 0 var configService *config.ConfigService -var versionInfo = version.Info{CurrentVersion: "v0.5.4"} +var versionInfo = version.Info{CurrentVersion: "v0.5.5"} //go:embed web var webFS embed.FS