From 250cc0ec0f453e43d8a8f66a47c236fb800cec4f Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Thu, 6 Dec 2018 00:29:38 +0300 Subject: [PATCH] config -- Avoid deleting existing dns section if someone removes schema_version from yaml file. --- config.go | 1 + upgrade.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 8facc405..407fcc7a 100644 --- a/config.go +++ b/config.go @@ -72,6 +72,7 @@ var config = configuration{ {Filter: dnsfilter.Filter{ID: 3}, Enabled: false, URL: "https://hosts-file.net/ad_servers.txt", Name: "hpHosts - Ad and Tracking servers only"}, {Filter: dnsfilter.Filter{ID: 4}, Enabled: false, URL: "http://www.malwaredomainlist.com/hostslist/hosts.txt", Name: "MalwareDomainList.com Hosts List"}, }, + SchemaVersion: currentSchemaVersion, } // Loads configuration from the YAML file diff --git a/upgrade.go b/upgrade.go index 1b8c6e34..21d7686d 100644 --- a/upgrade.go +++ b/upgrade.go @@ -126,8 +126,10 @@ func upgradeSchema1to2(diskConfig *map[string]interface{}) error { } } - (*diskConfig)["dns"] = (*diskConfig)["coredns"] - delete((*diskConfig), "coredns") + if _, ok := (*diskConfig)["dns"]; !ok { + (*diskConfig)["dns"] = (*diskConfig)["coredns"] + delete((*diskConfig), "coredns") + } (*diskConfig)["schema_version"] = 2 return nil