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
This commit is contained in:
parent
10ca1e7646
commit
b7191e3a6f
1 changed files with 2 additions and 20 deletions
|
|
@ -37,12 +37,7 @@ func CheckForUpdate(client *api.Client, stateFilePath, repo, currentVersion stri
|
|||
|
||||
func getLatestReleaseInfo(client *api.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {
|
||||
stateEntry, err := getStateEntry(stateFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
checkedRecently := time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24
|
||||
if checkedRecently {
|
||||
if err == nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
|
||||
return &stateEntry.LatestRelease, nil
|
||||
}
|
||||
|
||||
|
|
@ -63,20 +58,7 @@ func getLatestReleaseInfo(client *api.Client, stateFilePath, repo, currentVersio
|
|||
func getStateEntry(stateFilePath string) (*StateEntry, error) {
|
||||
content, err := ioutil.ReadFile(stateFilePath)
|
||||
if err != nil {
|
||||
// State files doesn't exist, so create one with default values.
|
||||
lastWeek := time.Now().Add(-time.Hour * 24 * 7)
|
||||
data := StateEntry{
|
||||
CheckedForUpdateAt: lastWeek,
|
||||
LatestRelease: ReleaseInfo{
|
||||
Version: "v0.0.0",
|
||||
URL: "<?>",
|
||||
},
|
||||
}
|
||||
content, err = yaml.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ioutil.WriteFile(stateFilePath, content, 0600)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var stateEntry StateEntry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue