()
| 41 | } |
| 42 | |
| 43 | func startProfileUpdateChecker() error { |
| 44 | module.mgr.Go("update active profiles", func(ctx *mgr.WorkerCtx) (err error) { |
| 45 | profilesSub, err := profileDB.Subscribe(query.New(ProfilesDBPath)) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | defer func() { |
| 50 | err := profilesSub.Cancel() |
| 51 | if err != nil { |
| 52 | log.Warningf("profile: failed to cancel subscription for updating active profiles: %s", err) |
| 53 | } |
| 54 | }() |
| 55 | |
| 56 | profileFeed: |
| 57 | for { |
| 58 | select { |
| 59 | case r := <-profilesSub.Feed: |
| 60 | // Check if subscription was canceled. |
| 61 | if r == nil { |
| 62 | return errors.New("subscription canceled") |
| 63 | } |
| 64 | |
| 65 | scopedID := strings.TrimPrefix(r.Key(), ProfilesDBPath) |
| 66 | |
| 67 | // Check if fingerprints changed such that the profile ID needs to be |
| 68 | // re-derived. This must run before the activeProfile lookup so that it |
| 69 | // also applies when the app is not currently running. |
| 70 | if !r.Meta().IsDeleted() { |
| 71 | if receivedProfile, parseErr := EnsureProfile(r); parseErr == nil && !receivedProfile.savedInternally { |
| 72 | if len(receivedProfile.Fingerprints) > 0 && |
| 73 | DeriveProfileID(receivedProfile.Fingerprints) != receivedProfile.ID { |
| 74 | if renameErr := migrateProfileOnFingerprintChange(receivedProfile); renameErr != nil { |
| 75 | log.Errorf("profile: failed to rename profile %s after fingerprint change: %s", scopedID, renameErr) |
| 76 | } |
| 77 | // The rename saves a new profile and deletes the old one, each of |
| 78 | // which produces its own feed event. Skip further processing here. |
| 79 | continue profileFeed |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Get active profile. |
| 85 | activeProfile := getActiveProfile(scopedID) |
| 86 | if activeProfile == nil { |
| 87 | // Check if profile is being deleted. |
| 88 | if r.Meta().IsDeleted() { |
| 89 | meta.MarkDeleted(scopedID) |
| 90 | } |
| 91 | |
| 92 | // Don't do any additional actions if the profile is not active. |
| 93 | continue profileFeed |
| 94 | } |
| 95 | |
| 96 | // Always increase the revision counter of the layer profile. |
| 97 | // This marks previous connections in the UI as decided with outdated settings. |
| 98 | if activeProfile.layeredProfile != nil { |
| 99 | activeProfile.layeredProfile.increaseRevisionCounter(true) |
| 100 | } |
no test coverage detected