+checklocks:s.serverMutex
(ctx context.Context)
| 671 | |
| 672 | // +checklocks:s.serverMutex |
| 673 | func (s *Server) syncSourcesLocked(ctx context.Context) error { |
| 674 | sources := map[snapshot.SourceInfo]bool{} |
| 675 | |
| 676 | if s.rep != nil { |
| 677 | snapshotSources, err := snapshot.ListSources(ctx, s.rep) |
| 678 | if err != nil { |
| 679 | return errors.Wrap(err, "unable to list sources") |
| 680 | } |
| 681 | |
| 682 | policies, err := policy.ListPolicies(ctx, s.rep) |
| 683 | if err != nil { |
| 684 | return errors.Wrap(err, "unable to list sources") |
| 685 | } |
| 686 | |
| 687 | // user@host policy |
| 688 | userhostPol, _, _, err := policy.GetEffectivePolicy(ctx, s.rep, snapshot.SourceInfo{ |
| 689 | UserName: s.rep.ClientOptions().Username, |
| 690 | Host: s.rep.ClientOptions().Hostname, |
| 691 | }) |
| 692 | if err != nil { |
| 693 | return errors.Wrap(err, "unable to get user policy") |
| 694 | } |
| 695 | |
| 696 | s.setMaxParallelSnapshotsLocked(userhostPol.UploadPolicy.MaxParallelSnapshots.OrDefault(1)) |
| 697 | |
| 698 | for _, ss := range snapshotSources { |
| 699 | sources[ss] = true |
| 700 | } |
| 701 | |
| 702 | for _, pol := range policies { |
| 703 | if pol.Target().Path != "" && pol.Target().Host != "" && pol.Target().UserName != "" { |
| 704 | sources[pol.Target()] = true |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | // copy existing sources to a map, from which we will remove sources that are found |
| 710 | // in the repository |
| 711 | oldSourceManagers := maps.Clone(s.sourceManagers) |
| 712 | |
| 713 | for src := range sources { |
| 714 | if sm, ok := oldSourceManagers[src]; ok { |
| 715 | // pre-existing source, already has a manager |
| 716 | delete(oldSourceManagers, src) |
| 717 | sm.refreshStatus(ctx) |
| 718 | } else { |
| 719 | sm := newSourceManager(src, s, s.rep) |
| 720 | s.sourceManagers[src] = sm |
| 721 | |
| 722 | sm.start(ctx, s.isLocal(src)) |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // whatever is left in oldSourceManagers are managers for sources that don't exist anymore. |
| 727 | // stop source manager for sources no longer in the repo. |
| 728 | for _, sm := range oldSourceManagers { |
| 729 | sm.stop(ctx) |
| 730 | } |
no test coverage detected