Skip to content

Commit

Permalink
updates: save downloading if update file matches file size
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 8, 2024
1 parent f74da1a commit 596ed06
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/snclient/task_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (u *UpdateHandler) mainLoop() {
if interval > time.Duration(u.updateInterval) {
interval = time.Duration(u.updateInterval) * time.Second
}
log.Debugf("[updates] checking for updates every %s", interval.String())

for {
select {
Expand Down Expand Up @@ -332,12 +333,19 @@ func (u *UpdateHandler) chooseBestUpdate(updates []updatesAvailable, downgrade s
}
}

if forceUpdate {
log.Tracef("forced version is %f (channel: %s / %s)", bestVersion, best.channel, best.url)

return best
}

curVersion := utils.ParseVersion(u.snc.Version())
if bestVersion <= curVersion {
if forceUpdate {
return best
}
switch {
case bestVersion == curVersion:
log.Tracef("already at best version %f", curVersion)

return nil
case bestVersion < curVersion:
log.Tracef("best version %f is lower than current version %f", bestVersion, curVersion)

return nil
Expand Down Expand Up @@ -558,6 +566,18 @@ func (u *UpdateHandler) checkUpdateCustomURL(url string) (updates []updatesAvail
return nil, fmt.Errorf("request failed %s: got content length %d", url, resp.ContentLength)
}

// if the content-length matches our file size, assume there no new version
executable := GlobalMacros["exe-full"]
stat, err := os.Stat(executable)
if err != nil {
return nil, fmt.Errorf("stat: %s", err.Error())
}
if resp.ContentLength > 0 && resp.ContentLength == stat.Size() {
log.Tracef("[update] content size matches %s: %d vs. %s: %d", url, resp.ContentLength, executable, stat.Size())

return []updatesAvailable{{url: url, version: u.snc.Version()}}, nil
}

refresh := false
cacheEntry, cached := u.urlCache[url]
switch {
Expand Down

0 comments on commit 596ed06

Please sign in to comment.