Pull request 2004: 6176-conf-check-output

Squashed commit of the following:

commit bc2c99c77ef4899872d7cc628fdfd04a2190dd89
Merge: d2bd0c95a 2bb04094e
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Sep 11 16:36:47 2023 +0300

    Merge branch 'master' into 6176-conf-check-output

commit d2bd0c95a79567eebfada170cfcca8bdafad03cd
Merge: d2bb7b1a6 8b8ae8ffa
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Sep 11 14:10:09 2023 +0300

    Merge branch 'master' into 6176-conf-check-output

commit d2bb7b1a6e7812402ff5fbf2e4d2abf3f0effb54
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Sep 11 14:05:03 2023 +0300

    all: imp code

commit 160aa94b59e4dfd00cb1b09eb8d99d9eaf8d0892
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 8 13:30:39 2023 +0300

    all: add conf check output
This commit is contained in:
Stanislav Chzhen 2023-09-11 16:42:41 +03:00
parent 2bb04094e1
commit d18219395a
1 changed files with 13 additions and 7 deletions

View File

@ -113,9 +113,9 @@ func (u *Updater) Update(firstRun bool) (err error) {
log.Info("updater: updating")
defer func() {
if err != nil {
log.Error("updater: failed: %v", err)
log.Info("updater: failed")
} else {
log.Info("updater: finished")
log.Info("updater: finished successfully")
}
}()
@ -240,18 +240,24 @@ func (u *Updater) unpack() error {
// check returns an error if the configuration file couldn't be used with the
// version of AdGuard Home just downloaded.
func (u *Updater) check() error {
func (u *Updater) check() (err error) {
log.Debug("updater: checking configuration")
err := copyFile(u.confName, filepath.Join(u.updateDir, "AdGuardHome.yaml"))
err = copyFile(u.confName, filepath.Join(u.updateDir, "AdGuardHome.yaml"))
if err != nil {
return fmt.Errorf("copyFile() failed: %w", err)
}
const format = "executing configuration check command: %w %d:\n" +
"below is the output of configuration check:\n" +
"%s" +
"end of the output"
cmd := exec.Command(u.updateExeName, "--check-config")
err = cmd.Run()
if err != nil || cmd.ProcessState.ExitCode() != 0 {
return fmt.Errorf("exec.Command(): %s %d", err, cmd.ProcessState.ExitCode())
out, err := cmd.CombinedOutput()
code := cmd.ProcessState.ExitCode()
if err != nil || code != 0 {
return fmt.Errorf(format, err, code, out)
}
return nil