Pull request: 2546 updater fix

Merge in DNS/adguard-home from 2546-updater-fix to master

Closes .

Squashed commit of the following:

commit af243c9fad710efe099506fda281e628c3e5ec30
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jan 13 14:33:37 2021 +0300

    updater: fix go 1.14 compat

commit 742fba24b300ce51c04acb586996c3c75e56ea20
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jan 13 13:58:27 2021 +0300

    util: imp error check

commit c2bdbce8af657a7f4b7e05c018cfacba86e06753
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Jan 11 18:51:26 2021 +0300

    all: fix and refactor update checking
This commit is contained in:
Ainar Garipov 2021-01-13 16:18:51 +03:00
parent bba74859e2
commit 0d67aa251d
18 changed files with 669 additions and 465 deletions
internal/home

View file

@ -12,7 +12,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/sysutil"
"github.com/AdguardTeam/AdGuardHome/internal/update"
"github.com/AdguardTeam/AdGuardHome/internal/updater"
"github.com/AdguardTeam/golibs/log"
)
@ -47,13 +47,13 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
}
}
var info update.VersionInfo
var info updater.VersionInfo
for i := 0; i != 3; i++ {
func() {
Context.controlLock.Lock()
defer Context.controlLock.Unlock()
info, err = Context.updater.GetVersionResponse(req.RecheckNow)
info, err = Context.updater.VersionInfo(req.RecheckNow)
}()
if err != nil {
@ -75,7 +75,9 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
break
}
if err != nil {
httpError(w, http.StatusBadGateway, "Couldn't get version check json from %s: %T %s\n", versionCheckURL, err, err)
vcu := Context.updater.VersionCheckURL()
httpError(w, http.StatusBadGateway, "Couldn't get version check json from %s: %T %s\n", vcu, err, err)
return
}
@ -88,12 +90,12 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
// Perform an update procedure to the latest available version
func handleUpdate(w http.ResponseWriter, _ *http.Request) {
if len(Context.updater.NewVersion) == 0 {
if Context.updater.NewVersion() == "" {
httpError(w, http.StatusBadRequest, "/update request isn't allowed now")
return
}
err := Context.updater.DoUpdate()
err := Context.updater.Update()
if err != nil {
httpError(w, http.StatusInternalServerError, "%s", err)
return
@ -108,7 +110,7 @@ func handleUpdate(w http.ResponseWriter, _ *http.Request) {
}
// Convert version.json data to our JSON response
func getVersionResp(info update.VersionInfo) []byte {
func getVersionResp(info updater.VersionInfo) []byte {
ret := make(map[string]interface{})
ret["can_autoupdate"] = false
ret["new_version"] = info.NewVersion