Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package version

import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -56,14 +54,12 @@ func ShouldCrioWipe(versionFileName string) (bool, error) {

// shouldCrioWipe is an internal function for testing purposes
func shouldCrioWipe(versionFileName, versionString string) (bool, error) {
f, err := os.Open(versionFileName)
if err != nil {
return true, errors.Errorf("version file %s not found: %v", versionFileName, err)
if versionFileName == "" {
return false, nil
}
r := bufio.NewReader(f)
versionBytes, err := ioutil.ReadAll(r)
versionBytes, err := os.ReadFile(versionFileName)
if err != nil {
return true, errors.Errorf("reading version file %s failed: %v", versionFileName, err)
return true, errors.Errorf("version file %s not found: %v", versionFileName, err)
}

// parse the version that was laid down by a previous invocation of crio
Expand Down Expand Up @@ -99,6 +95,9 @@ func LogVersion() {

// writeVersionFile is an internal function for testing purposes
func writeVersionFile(file, gitCommit, version string) error {
if file == "" {
return nil
}
current, err := parseVersionConstant(version, gitCommit)
// Sanity check-this should never happen
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ var _ = t.Describe("Version", func() {
_, err = ioutil.ReadFile(filename)
Expect(err).To(BeNil())
})
It("should fail to upgrade with unspecified version", func() {
It("should not wipe with empty version file", func() {
upgrade, err := shouldCrioWipe("", tempVersion)
Expect(upgrade).To(BeTrue())
Expect(err).ToNot(BeNil())
Expect(upgrade).To(BeFalse())
Expect(err).To(BeNil())
})
It("should fail to upgrade with empty version file", func() {
tempFileName := tempFileName
Expand Down