lib/ur: Don't report uptime if start time is in the past (fixes #7698) (#8996)

Currently, because of devices with unset RTC clock, the 100% percentile
for Uptime on [1] is calculated since the Unix epoch which is useless as
far as usage statistics are concerned. Thus, if the Syncthing start time
is set to a past date, assume that the clock is wrong and do not even
try to report the uptime.

[1] https://data.syncthing.net

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
tomasz1986 2023-07-22 23:25:03 +02:00 committed by GitHub
parent 6b6b2c6194
commit f42f041f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -328,6 +328,11 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
}
func (*Service) UptimeS() int {
// Handle nonexistent or wildly incorrect system clock.
// This code was written in 2023, it can't run in the past.
if StartTime.Year() < 2023 {
return 0
}
return int(time.Since(StartTime).Seconds())
}