MCPcopy
hub / github.com/kopia/kopia / maybeCheckGithub

Method maybeCheckGithub

cli/update_check.go:197–232  ·  view source on GitHub ↗
(ctx context.Context, us *updateState)

Source from the content-addressed store, hash-verified

195}
196
197func (c *App) maybeCheckGithub(ctx context.Context, us *updateState) error {
198 if !clock.Now().After(us.NextCheckTime) {
199 return nil
200 }
201
202 log(ctx).Debug("time for next update check has been reached")
203
204 // before we check for update, write update state file again, so if this fails
205 // we won't bother GitHub for a while
206 us.NextCheckTime = clock.Now().Add(c.updateCheckInterval)
207 if err := c.writeUpdateState(us); err != nil {
208 return errors.Wrap(err, "unable to write update state")
209 }
210
211 newAvailableVersion, err := getLatestReleaseNameFromGitHub(ctx)
212 if err != nil {
213 return errors.Wrap(err, "update to get the latest release from GitHub")
214 }
215
216 log(ctx).Debugf("latest version on GitHub: %v previous %v", newAvailableVersion, us.AvailableVersion)
217
218 // we got updated version from GitHub, write it in a state file again
219 if newAvailableVersion != us.AvailableVersion {
220 if err = verifyGitHubReleaseIsComplete(ctx, newAvailableVersion); err != nil {
221 return errors.Wrap(err, "unable to validate GitHub release")
222 }
223
224 us.AvailableVersion = newAvailableVersion
225
226 if err := c.writeUpdateState(us); err != nil {
227 return errors.Wrap(err, "unable to write update state")
228 }
229 }
230
231 return nil
232}
233
234// maybePrintUpdateNotification prints notification about available version.
235func (c *App) maybePrintUpdateNotification(ctx context.Context) {

Callers 1

maybeCheckForUpdatesMethod · 0.95

Calls 6

writeUpdateStateMethod · 0.95
NowFunction · 0.92
AfterMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected