SnapshotChanged checks whether any config file has changed since the last reload by comparing os.Stat results against the stored snapshot.
(paths []string)
| 428 | // since the last reload by comparing os.Stat results against |
| 429 | // the stored snapshot. |
| 430 | func (m *Manager) SnapshotChanged(paths []string) bool { |
| 431 | seen := make(map[string]struct{}, len(paths)) |
| 432 | unique := make([]string, 0, len(paths)) |
| 433 | for _, p := range paths { |
| 434 | if _, ok := seen[p]; !ok { |
| 435 | seen[p] = struct{}{} |
| 436 | unique = append(unique, p) |
| 437 | } |
| 438 | } |
| 439 | paths = unique |
| 440 | |
| 441 | m.mu.RLock() |
| 442 | snap := maps.Clone(m.snapshot) |
| 443 | snapshotLen := len(snap) |
| 444 | m.mu.RUnlock() |
| 445 | |
| 446 | if len(paths) != snapshotLen { |
| 447 | return true |
| 448 | } |
| 449 | |
| 450 | for _, p := range paths { |
| 451 | prev, ok := snap[p] |
| 452 | if !ok { |
| 453 | return true |
| 454 | } |
| 455 | |
| 456 | info, err := os.Stat(p) |
| 457 | if err != nil { |
| 458 | // Stat failed; changed only if the file existed before. |
| 459 | if prev.exists { |
| 460 | return true |
| 461 | } |
| 462 | continue |
| 463 | } |
| 464 | |
| 465 | // Stat succeeded but file was absent before: it appeared. |
| 466 | if !prev.exists { |
| 467 | return true |
| 468 | } |
| 469 | |
| 470 | if !info.ModTime().Equal(prev.modTime) || info.Size() != prev.size { |
| 471 | return true |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return false |
| 476 | } |
| 477 | |
| 478 | // serverDiff is the output of classifyServers: which servers to |
| 479 | // connect, which to close, which to keep, and a snapshot of the |