chore(storage): ignore persisted servers data with a timestamp in the future

- force users to set a timestamp as the current one if manually editing servers.json which they should not do anyway
- favor future servers data updates through a container image pull to override older user-defined data
This commit is contained in:
Quentin McGaw
2025-12-23 15:38:17 +00:00
parent 600f2ab643
commit 617f1b764f
+7 -1
View File
@@ -1,6 +1,7 @@
package storage
import (
"fmt"
"sort"
"time"
@@ -29,7 +30,12 @@ func (s *Storage) mergeServers(hardcoded, persisted models.AllServers) models.Al
func (s *Storage) mergeProviderServers(provider string,
hardcoded, persisted models.Servers,
) (merged models.Servers) {
if persisted.Timestamp > hardcoded.Timestamp {
nowTimestamp := time.Now().Unix()
if persisted.Timestamp > nowTimestamp {
s.logger.Warn(fmt.Sprintf(
"persisted %s servers have a timestamp %d in the future, ignoring them",
provider, persisted.Timestamp))
} else if persisted.Timestamp > hardcoded.Timestamp {
diff := time.Unix(persisted.Timestamp, 0).Sub(time.Unix(hardcoded.Timestamp, 0))
if diff < 0 {
diff = -diff