(ctx context.Context, bb *merger.BidirectionalPatch, dryRun bool, force bool, rootsInfo map[string]*model.EndpointRootStat)
| 166 | } |
| 167 | |
| 168 | func (s *Sync) runBi(ctx context.Context, bb *merger.BidirectionalPatch, dryRun bool, force bool, rootsInfo map[string]*model.EndpointRootStat) error { |
| 169 | |
| 170 | source, _ := model.AsPathSyncSource(s.Source) |
| 171 | targetAsSource, _ := model.AsPathSyncSource(s.Target) |
| 172 | |
| 173 | var useSnapshots, captureSnapshots bool |
| 174 | var leftSnap, rightSnap model.Snapshoter |
| 175 | var leftPatches, rightPatches map[string]merger.Patch |
| 176 | |
| 177 | var roots []string |
| 178 | roots = append(roots, s.Roots...) |
| 179 | |
| 180 | if len(roots) == 0 { |
| 181 | roots = append(roots, "/") |
| 182 | } |
| 183 | |
| 184 | if s.snapshotFactory != nil && !force { |
| 185 | var er1, er2 error |
| 186 | wg := &sync.WaitGroup{} |
| 187 | wg.Add(2) |
| 188 | go func() { |
| 189 | defer wg.Done() |
| 190 | leftSnap, leftPatches, er1 = s.patchesFromSnapshot(ctx, "left", source, roots, rootsInfo) |
| 191 | }() |
| 192 | go func() { |
| 193 | defer wg.Done() |
| 194 | rightSnap, rightPatches, er2 = s.patchesFromSnapshot(ctx, "right", targetAsSource, roots, rootsInfo) |
| 195 | }() |
| 196 | wg.Wait() |
| 197 | if er1 == nil && er2 == nil { |
| 198 | if leftSnap.IsEmpty() || rightSnap.IsEmpty() { |
| 199 | captureSnapshots = true |
| 200 | } else { |
| 201 | useSnapshots = true |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if useSnapshots { |
| 207 | |
| 208 | log.Logger(ctx).Info("Computing patches from Snapshots") |
| 209 | for _, r := range roots { |
| 210 | b, e := merger.ComputeBidirectionalPatch(ctx, leftPatches[r], rightPatches[r]) |
| 211 | if b != nil { |
| 212 | bb.AppendBranch(ctx, b) |
| 213 | } |
| 214 | if e != nil { |
| 215 | return bb.SetPatchError(e) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | } else { |
| 220 | |
| 221 | bb.SkipFilterToTarget(true) |
| 222 | |
| 223 | log.Logger(ctx).Info("Computing patches from Sources") |
| 224 | for _, r := range roots { |
| 225 | diff := merger.NewDiff(source, targetAsSource) |
no test coverage detected