MCPcopy Create free account
hub / github.com/pydio/cells / runBi

Method runBi

common/sync/task/sync-run.go:168–261  ·  view source on GitHub ↗
(ctx context.Context, bb *merger.BidirectionalPatch, dryRun bool, force bool, rootsInfo map[string]*model.EndpointRootStat)

Source from the content-addressed store, hash-verified

166}
167
168func (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)

Callers 1

runMethod · 0.95

Calls 15

patchesFromSnapshotMethod · 0.95
IsEmptyMethod · 0.95
ComputeMethod · 0.95
monitorDiffMethod · 0.95
ToBidirectionalPatchMethod · 0.95
CaptureMethod · 0.95
AsPathSyncSourceFunction · 0.92
LoggerFunction · 0.92
NewDiffFunction · 0.92
AsPathSyncTargetFunction · 0.92
WaitMethod · 0.80

Tested by

no test coverage detected