Skip to content

Commit b7191e3

Browse files
committed
Simplify case when state.yml is non-existent or corrupt
- non-existent file simply returns an error - corrupt file (e.g. YAML unmarshal error) also returns an error - if there were errors, just check for new release normally instead of aborting
1 parent 10ca1e7 commit b7191e3

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

update/update.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ func CheckForUpdate(client *api.Client, stateFilePath, repo, currentVersion stri
3737

3838
func getLatestReleaseInfo(client *api.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {
3939
stateEntry, err := getStateEntry(stateFilePath)
40-
if err != nil {
41-
return nil, err
42-
}
43-
44-
checkedRecently := time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24
45-
if checkedRecently {
40+
if err == nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
4641
return &stateEntry.LatestRelease, nil
4742
}
4843

@@ -63,20 +58,7 @@ func getLatestReleaseInfo(client *api.Client, stateFilePath, repo, currentVersio
6358
func getStateEntry(stateFilePath string) (*StateEntry, error) {
6459
content, err := ioutil.ReadFile(stateFilePath)
6560
if err != nil {
66-
// State files doesn't exist, so create one with default values.
67-
lastWeek := time.Now().Add(-time.Hour * 24 * 7)
68-
data := StateEntry{
69-
CheckedForUpdateAt: lastWeek,
70-
LatestRelease: ReleaseInfo{
71-
Version: "v0.0.0",
72-
URL: "<?>",
73-
},
74-
}
75-
content, err = yaml.Marshal(data)
76-
if err != nil {
77-
return nil, err
78-
}
79-
ioutil.WriteFile(stateFilePath, content, 0600)
61+
return nil, err
8062
}
8163

8264
var stateEntry StateEntry

0 commit comments

Comments
 (0)