Skip to content

Commit 7c8fbd8

Browse files
committed
feat: add checksums check to updater
1 parent 3ac7851 commit 7c8fbd8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

internal/updater/periodic.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package updater
22

33
import (
4+
"github.com/creativeprojects/go-selfupdate"
45
"github.com/vumm/cli/internal/common"
56
"github.com/vumm/cli/internal/config"
67
"os"
@@ -10,6 +11,14 @@ import (
1011

1112
const updateInterval = time.Hour * 24 * 7 // 1 week
1213

14+
func PeriodicCheckForUpdates() (*selfupdate.Release, bool, error) {
15+
if !shouldCheck() {
16+
return nil, false, nil
17+
}
18+
19+
return CheckForUpdates()
20+
}
21+
1322
func shouldCheck() bool {
1423
// Don't check for updates on development versions
1524
if !common.IsRelease() {

internal/updater/updater.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import (
1111
)
1212

1313
var latestVersion *selfupdate.Release
14+
var updater *selfupdate.Updater
1415

15-
func PeriodicCheckForUpdates() (*selfupdate.Release, bool, error) {
16-
if !shouldCheck() {
17-
return nil, false, nil
16+
func init() {
17+
var err error
18+
updater, err = selfupdate.NewUpdater(selfupdate.Config{Validator: &selfupdate.ChecksumValidator{UniqueFilename: "checksums.txt"}})
19+
if err != nil {
20+
panic(err)
1821
}
19-
20-
return CheckForUpdates()
2122
}
2223

2324
func CheckForUpdates() (*selfupdate.Release, bool, error) {
24-
latest, found, err := selfupdate.DetectLatest("BF3RM/vumm-cli")
25+
latest, found, err := updater.DetectLatest("BF3RM/vumm-cli")
2526
if err != nil {
2627
return nil, false, fmt.Errorf("failed to fetch latest version: %v", err)
2728
}
@@ -58,7 +59,7 @@ func SelfUpdate() (bool, error) {
5859
if err != nil {
5960
return false, errors.New("could not locate executable path")
6061
}
61-
if err := selfupdate.DefaultUpdater().UpdateTo(latestVersion, exe); err != nil {
62+
if err := updater.UpdateTo(latestVersion, exe); err != nil {
6263
return false, fmt.Errorf("error occurred while updating binary: %v", err)
6364
}
6465
log.Printf("Successfully updated to version %s", latestVersion.Version())

0 commit comments

Comments
 (0)