GODT-976 Exclude updates from clearing cache and clear cache, including updates, while switching early access off

This commit is contained in:
Michal Horejsek
2021-01-27 09:16:04 +01:00
parent c6107dbd4b
commit 7468ed7dc0
18 changed files with 241 additions and 13 deletions

View File

@ -17,8 +17,16 @@
package versioner
import "github.com/Masterminds/semver/v3"
// RemoveOldVersions removes all but the latest app version.
func (v *Versioner) RemoveOldVersions() error {
// darwin does not use the versioner; removal is a noop.
return nil
}
// RemoveOtherVersions removes all but the specific provided app version.
func (v *Versioner) RemoveOtherVersions(versionToKeep *semver.Version) error {
// darwin does not use the versioner; removal is a noop.
return nil
}

View File

@ -22,6 +22,7 @@ package versioner
import (
"os"
"github.com/Masterminds/semver/v3"
"github.com/sirupsen/logrus"
)
@ -45,3 +46,22 @@ func (v *Versioner) RemoveOldVersions() error {
return nil
}
// RemoveOtherVersions removes all but the specific provided app version.
func (v *Versioner) RemoveOtherVersions(versionToKeep *semver.Version) error {
versions, err := v.ListVersions()
if err != nil {
return err
}
for _, version := range versions {
if version.Equal(versionToKeep) {
continue
}
if err := os.RemoveAll(version.path); err != nil {
logrus.WithError(err).Error("Failed to remove old app version")
}
}
return nil
}

View File

@ -55,6 +55,10 @@ func (v *Version) String() string {
return fmt.Sprintf("%v", v.version)
}
func (v *Version) Equal(version *semver.Version) bool {
return v.version.Equal(version)
}
// VerifyFiles verifies all files in the version directory.
func (v *Version) VerifyFiles(kr *crypto.KeyRing) error {
fileBytes, err := ioutil.ReadFile(filepath.Join(v.path, sumFile)) // nolint[gosec]