From 1792fd3e0f2a7a73536e2bdb29973074be8adf57 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 10 Jan 2020 12:40:16 +0300 Subject: [PATCH] * auto-update: check if executable file exists --- home/control_update.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/home/control_update.go b/home/control_update.go index b1847754..02c1fec0 100644 --- a/home/control_update.go +++ b/home/control_update.go @@ -148,6 +148,15 @@ type updateInfo struct { newBinName string // Full path to the new executable file } +// Return TRUE if file exists +func fileExists(fn string) bool { + _, err := os.Stat(fn) + if err != nil { + return false + } + return true +} + // Fill in updateInfo object func getUpdateInfo(jsonData []byte) (*updateInfo, error) { var u updateInfo @@ -190,6 +199,9 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) { binName = "AdGuardHome.exe" } u.curBinName = filepath.Join(workDir, binName) + if !fileExists(u.curBinName) { + return nil, fmt.Errorf("Executable file %s doesn't exist", u.curBinName) + } u.bkpBinName = filepath.Join(u.backupDir, binName) u.newBinName = filepath.Join(u.updateDir, "AdGuardHome", binName) if strings.HasSuffix(pkgFileName, ".zip") {