Skip to content
Snippets Groups Projects

Hotfix/version update check

Merged Jono Wenger requested to merge hotfix/versionUpdateCheck into release
All threads resolved!
Files
3
+ 51
3
@@ -11,9 +11,11 @@ package storage
import (
"os"
"sync"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/bindings"
)
@@ -38,17 +40,23 @@ func CheckAndStoreVersions() error {
func checkAndStoreVersions(
currentWasmVer, currentClientVer string, ls *LocalStorage) error {
// Get the stored client and WASM versions, if they exists
storedClientVer, err := initOrLoadStoredSemver(
clientVerKey, currentClientVer, ls)
// Get the stored client version, if it exists
storedClientVer, err :=
initOrLoadStoredSemver(clientVerKey, currentClientVer, ls)
if err != nil {
return err
}
// Get the stored WASM versions, if it exists
storedWasmVer, err := initOrLoadStoredSemver(semverKey, currentWasmVer, ls)
if err != nil {
return err
}
// Store old versions to memory
setOldClientSemVersion(storedClientVer)
setOldWasmSemVersion(storedWasmVer)
// Check if client needs an update
if storedClientVer != currentClientVer {
jww.INFO.Printf("xxDK client out of date; upgrading version: v%s → v%s",
@@ -96,3 +104,43 @@ func initOrLoadStoredSemver(
// Return the stored version
return string(storedVersion), nil
}
// oldVersions contains the old versions of xxdk WASM and xxdk client that were
// stored in storage before being overwritten on update.
var oldVersions struct {
wasm string
client string
sync.Mutex
}
// GetOldWasmSemVersion returns the old version of xxdk WASM before being
// updated.
func GetOldWasmSemVersion() string {
oldVersions.Lock()
defer oldVersions.Unlock()
return oldVersions.wasm
}
// GetOldClientSemVersion returns the old version of xxdk client before being
// updated.
func GetOldClientSemVersion() string {
oldVersions.Lock()
defer oldVersions.Unlock()
return oldVersions.client
}
// setOldWasmSemVersion sets the old version of xxdk WASM. This should be called
// before it is updated.
func setOldWasmSemVersion(v string) {
oldVersions.Lock()
defer oldVersions.Unlock()
oldVersions.wasm = v
}
// setOldClientSemVersion sets the old version of xxdk client. This should be
// called before it is updated.
func setOldClientSemVersion(v string) {
oldVersions.Lock()
defer oldVersions.Unlock()
oldVersions.client = v
}
Loading