-
Notifications
You must be signed in to change notification settings - Fork 33
/
mapper.go
796 lines (663 loc) · 20 KB
/
mapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
package vcs
// NOTE ON CODING STYLE:
// If you modify something in here, make sure to always
// incude "src" or "dst" in the symbol name to indicate
// to which side of the sync/diff this symbol belongs!
// Too many hours have been spent on confused debugging.
import (
"fmt"
"path"
e "github.com/pkg/errors"
c "github.com/sahib/brig/catfs/core"
ie "github.com/sahib/brig/catfs/errors"
n "github.com/sahib/brig/catfs/nodes"
"github.com/sahib/brig/util/trie"
log "github.com/sirupsen/logrus"
)
// MapPair is a pair of nodes (a file or a directory)
// One of Src and Dst might be nil:
// - If Src is nil, the node was removed on the remote side.
// - If Dst is nil, the node was added on the remote side.
//
// Both shall never be nil at the same time.
//
// If TypeMismatch is true, nodes have a different type
// and need conflict resolution.
//
// If SrcWasRemoved is true, the node was deleted on the
// remote's side and we might need to propagate this remove.
// Otherwise, if src is nil, dst can be considered as missing
// file on src's side.
//
// If SrcWasMoved is true, the two nodes were purely moved,
// but not modified otherwise.
type MapPair struct {
Src n.ModNode
Dst n.ModNode
SrcWasRemoved bool
SrcWasMoved bool
TypeMismatch bool
}
// flags that are set during the mapper run.
// The zero value of this struct should mean "disabled".
type flags struct {
// The node was visited on the source side.
// This should prohibit duplicate visits.
srcVisited bool
// The file was already reported/tested equal on src side.
srcHandled bool
// The file was already reported/tested equal on dst side.
dstHandled bool
// The directory consists completely of other src reports.
srcComplete bool
// The directory consists completely of other dst reports.
dstComplete bool
}
// Mapper holds the state for the mapping algorithm.
type Mapper struct {
lkrSrc, lkrDst *c.Linker
srcRoot n.Node
srcHead *n.Commit
dstHead *n.Commit
flagsRoot *trie.Node
fn func(pair MapPair) error
}
func (ma *Mapper) getFlags(path string) *flags {
child := ma.flagsRoot.Lookup(path)
if child == nil {
child = ma.flagsRoot.InsertWithData(path, &flags{})
}
if child.Data == nil {
child.Data = &flags{}
}
return child.Data.(*flags)
}
func (ma *Mapper) setSrcVisited(nd n.Node) {
ma.getFlags(nd.Path()).srcVisited = true
}
func (ma *Mapper) setSrcHandled(nd n.Node) {
ma.getFlags(nd.Path()).srcHandled = true
}
func (ma *Mapper) setDstHandled(nd n.Node) {
ma.getFlags(nd.Path()).dstHandled = true
}
func (ma *Mapper) setSrcComplete(nd n.Node) {
ma.getFlags(nd.Path()).srcComplete = true
}
func (ma *Mapper) setDstComplete(nd n.Node) {
ma.getFlags(nd.Path()).dstComplete = true
}
func (ma *Mapper) isSrcVisited(nd n.Node) bool {
return ma.getFlags(nd.Path()).srcVisited
}
func (ma *Mapper) isSrcHandled(nd n.Node) bool {
return ma.getFlags(nd.Path()).srcHandled
}
func (ma *Mapper) isDstHandled(nd n.Node) bool {
return ma.getFlags(nd.Path()).dstHandled
}
func (ma *Mapper) isSrcComplete(nd n.Node) bool {
return ma.getFlags(nd.Path()).srcComplete
}
func (ma *Mapper) isDstComplete(nd n.Node) bool {
return ma.getFlags(nd.Path()).dstComplete
}
////////////////////
func (ma *Mapper) report(src, dst n.ModNode, typeMismatch, isRemove, isMove bool) error {
if src != nil {
ma.setSrcHandled(src)
}
if dst != nil {
ma.setDstHandled(dst)
}
debug("=> report", src, dst)
return ma.fn(MapPair{
Src: src,
Dst: dst,
TypeMismatch: typeMismatch,
SrcWasRemoved: isRemove,
SrcWasMoved: isMove,
})
}
func (ma *Mapper) reportByType(src, dst n.ModNode) error {
if src == nil || dst == nil {
return ma.report(src, dst, false, false, false)
}
isTypeMismatch := src.Type() != dst.Type()
if src.ContentHash().Equal(dst.ContentHash()) {
// If the files are equal, but the location changed,
// the file were moved.
if src.Path() != dst.Path() {
return ma.report(src, dst, isTypeMismatch, false, true)
}
// The files appear to be equal.
// We need to remember to not output them again.
ma.setSrcHandled(src)
ma.setDstHandled(dst)
return nil
}
return ma.report(src, dst, isTypeMismatch, false, false)
}
func (ma *Mapper) mapFile(srcCurr *n.File, dstFilePath string) error {
// Check if we already visited this file.
if ma.isSrcVisited(srcCurr) {
return nil
}
debug("map file", srcCurr.Path(), dstFilePath)
// Remember that we visited this node.
ma.setSrcVisited(srcCurr)
dstCurr, err := ma.lkrDst.LookupNodeAt(ma.dstHead, dstFilePath)
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
if dstCurr == nil {
// We do not have this node yet, mark it for copying.
return ma.report(srcCurr, nil, false, false, false)
}
switch typ := dstCurr.Type(); typ {
case n.NodeTypeDirectory:
// Our node seems to be a directory and theirs a file.
// That's not something we can fix.
dstDir, ok := dstCurr.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
// File and Directory don't go well together.
return ma.report(srcCurr, dstDir, true, false, false)
case n.NodeTypeFile:
// We have two competing files.
dstFile, ok := dstCurr.(*n.File)
if !ok {
return ie.ErrBadNode
}
return ma.reportByType(srcCurr, dstFile)
case n.NodeTypeGhost:
// It's still possible that the file was moved on our side.
aliveDstCurr, err := ma.ghostToAlive(ma.lkrDst, ma.dstHead, dstCurr)
if err != nil {
return err
}
return ma.reportByType(srcCurr, aliveDstCurr)
default:
return e.Wrapf(ie.ErrBadNode, "Unexpected node type in syncFile: %v", typ)
}
}
func (ma *Mapper) mapDirectoryContents(srcCurr *n.Directory, dstPath string) error {
srcChildren, err := srcCurr.ChildrenSorted(ma.lkrSrc)
if err != nil {
return err
}
for _, srcChild := range srcChildren {
childDstPath := path.Join(dstPath, srcChild.Name())
switch srcChild.Type() {
case n.NodeTypeDirectory:
srcChildDir, ok := srcChild.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
if err := ma.mapDirectory(srcChildDir, childDstPath, false); err != nil {
return err
}
case n.NodeTypeFile:
srcChildFile, ok := srcChild.(*n.File)
if !ok {
return ie.ErrBadNode
}
if err := ma.mapFile(srcChildFile, childDstPath); err != nil {
return err
}
case n.NodeTypeGhost:
// remote ghosts are ignored, since they were handled beforehand.
default:
return ie.ErrBadNode
}
}
return nil
}
func (ma *Mapper) mapDirectory(srcCurr *n.Directory, dstPath string, force bool) error {
if !force {
if ma.isSrcVisited(srcCurr) {
return nil
}
}
log.Debugf("mapping dir %s <-> %s", srcCurr.Path(), dstPath)
ma.setSrcVisited(srcCurr)
dstCurrNd, err := ma.lkrDst.LookupModNodeAt(ma.dstHead, dstPath)
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
if dstCurrNd == nil {
// We never heard of this directory apparently. Go sync it.
return ma.report(srcCurr, nil, false, false, false)
}
// Special case: The node might have been moved on dst's side.
// We might notice this, if dst type is a ghost.
if dstCurrNd.Type() == n.NodeTypeGhost {
aliveDstCurr, err := ma.ghostToAlive(ma.lkrDst, ma.dstHead, dstCurrNd)
if err != nil {
return err
}
// No sibling found for this ghost.
if aliveDstCurr == nil {
return ma.report(srcCurr, nil, false, false, false)
}
localBackCheck, err := ma.lkrSrc.LookupNodeAt(ma.srcHead, aliveDstCurr.Path())
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
if localBackCheck == nil || localBackCheck.Type() == n.NodeTypeGhost {
// Delete the guard again, due to the recursive call.
return ma.mapDirectory(srcCurr, aliveDstCurr.Path(), true)
}
return ma.report(srcCurr, nil, false, false, false)
}
if dstCurrNd.Type() != n.NodeTypeDirectory {
return ma.report(srcCurr, dstCurrNd, true, false, false)
}
dstCurr, ok := dstCurrNd.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
// Check if we're lucky and the directory hash is equal:
if srcCurr.ContentHash().Equal(dstCurr.ContentHash()) {
// Remember that we visited this subtree.
ma.setSrcHandled(srcCurr)
ma.setDstHandled(dstCurr)
log.Debugf(
"%s and %s have the same content; skipping",
srcCurr.Path(),
dstCurr.Path(),
)
if srcCurr.Path() != dstCurr.Path() {
return ma.report(srcCurr, dstCurr, false, false, true)
}
// If they even have the same tree hash, we can be sure that both
// use the same path layout even. No work to do in this case.
if srcCurr.TreeHash().Equal(dstCurr.TreeHash()) {
return nil
}
}
// Both sides have this directory, but the content differs.
// We need to figure out recursively what exactly is different.
return ma.mapDirectoryContents(srcCurr, dstPath)
}
func (ma *Mapper) ghostToAlive(lkr *c.Linker, head *n.Commit, nd n.Node) (n.ModNode, error) {
partnerNd, _, err := lkr.MoveEntryPoint(nd)
if err != nil {
return nil, e.Wrap(err, "move entry point")
}
// No move partner found.
if partnerNd == nil {
return nil, nil
}
// We want to go forward in history.
// In theory, the other direction should not happen,
// since we're always operating on ghosts here.
// if moveDir != c.MoveDirDstToSrc {
// log.Debugf("bad move direction")
// return nil, nil
// }
// Go forward to the most recent version of this node.
// This is no guarantee yet that this node is reachable
// from the head commit (it might have been removed...)
mostRecent, err := lkr.NodeByInode(partnerNd.Inode())
if err != nil {
return nil, err
}
if mostRecent == nil {
err = fmt.Errorf("mapper: No such node with inode %d", partnerNd.Inode())
return nil, err
}
// This should usually not happen, but just to be sure.
if mostRecent.Type() == n.NodeTypeGhost {
return nil, nil
}
reacheable, err := lkr.LookupNodeAt(head, mostRecent.Path())
if err != nil && !ie.IsNoSuchFileError(err) {
return nil, e.Wrapf(err, "ghost2alive: lookupAt")
}
if reacheable == nil {
return nil, nil
}
if reacheable.Inode() != mostRecent.Inode() {
// The node is still reachable, but it was changed
// (i.e. by removing and re-adding it -> different inode)
return nil, nil
}
reacheableModNd, ok := reacheable.(n.ModNode)
if !ok {
return nil, ie.ErrBadNode
}
return reacheableModNd, nil
}
type ghostDir struct {
// source directory.
srcDir *n.Directory
// mapped path in lkrDst
dstPath string
}
func (ma *Mapper) handleGhostsWithoutAliveNd(srcNd n.Node) error {
dstNd, err := ma.lkrDst.LookupNodeAt(ma.dstHead, srcNd.Path())
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
// Check if we maybe already removed or moved the node:
if dstNd != nil && dstNd.Type() != n.NodeTypeGhost {
dstModNd, ok := dstNd.(n.ModNode)
if !ok {
return ie.ErrBadNode
}
// Report that the file is missing on src's side.
return ma.report(nil, dstModNd, false, true, false)
}
// does not exist on both sides, nothing to report.
return nil
}
func (ma *Mapper) extractGhostDirs() ([]ghostDir, error) {
movedSrcDirs := []ghostDir{}
return movedSrcDirs, n.Walk(ma.lkrSrc, ma.srcRoot, true, func(srcNd n.Node) error {
// Ignore everything that is not a ghost.
if srcNd.Type() != n.NodeTypeGhost {
return nil
}
aliveSrcNd, err := ma.ghostToAlive(ma.lkrSrc, ma.srcHead, srcNd)
if err != nil {
return err
}
if aliveSrcNd == nil {
// It's a ghost, but it has no living counterpart.
// This node *might* have been removed on the remote side.
// Try to see if we have a node at this path, the next step
// of sync then needs to decide if the node needs to be removed.
return ma.handleGhostsWithoutAliveNd(srcNd)
}
// At this point we know that the ghost related to a moved file.
// Check if we have a file at the same place.
dstNd, err := ma.lkrDst.LookupNodeAt(ma.dstHead, aliveSrcNd.Path())
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
if dstNd != nil && dstNd.Type() != n.NodeTypeGhost {
// The node already exists in our place. No way we can really merge
// it cleanly, so just handle the ghost as normal file and potentially
// apply the normal conflict resolution later on.
return nil
}
dstRefNd, err := ma.lkrDst.LookupNodeAt(ma.dstHead, srcNd.Path())
if err != nil && !ie.IsNoSuchFileError(err) {
return err
}
if dstRefNd != nil {
// Node maybe also moved. If so, try to resolve it to the full node:
if dstRefNd.Type() == n.NodeTypeGhost {
aliveOrig, err := ma.ghostToAlive(ma.lkrDst, ma.dstHead, dstRefNd)
if err != nil {
return err
}
dstRefNd = aliveOrig
}
}
// The node was removed on dst:
// We will detect the removal later.
if dstRefNd == nil {
return nil
}
dstRefModNd, ok := dstRefNd.(n.ModNode)
if !ok {
return e.Wrapf(ie.ErrBadNode, "dstRefModNd is not a file or directory: %v", dstRefNd)
}
switch aliveSrcNd.Type() {
case n.NodeTypeFile:
// Mark those both ghosts and original node as visited.
err = ma.mapFile(aliveSrcNd.(*n.File), dstRefModNd.Path())
ma.setSrcVisited(aliveSrcNd)
ma.setSrcVisited(srcNd)
return err
case n.NodeTypeDirectory:
// ma.setSrcVisited(srcNd)
if dstRefNd.Type() != n.NodeTypeDirectory {
return ma.report(aliveSrcNd, dstRefModNd, true, false, false)
}
aliveSrcDir, ok := aliveSrcNd.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
movedSrcDirs = append(movedSrcDirs, ghostDir{
srcDir: aliveSrcDir,
dstPath: dstRefNd.Path(),
})
return nil
default:
return e.Wrapf(ie.ErrBadNode, "Unexpected type in handle ghosts: %v", err)
}
})
}
func (ma *Mapper) handleGhosts() error {
movedSrcDirs, err := ma.extractGhostDirs()
if err != nil {
return err
}
// Handle moved paths after handling single files.
// (mapDirectory assumes that moved files in it were already handled).
for _, movedSrcDir := range movedSrcDirs {
log.Debugf("map: %v %v", movedSrcDir.srcDir.Path(), movedSrcDir.dstPath)
if err := ma.mapDirectory(movedSrcDir.srcDir, movedSrcDir.dstPath, false); err != nil {
return err
}
}
return nil
}
// NewMapper creates a new mapper object that is capable of finding pairs of
// nodes between lkrDst and lkrSrc.
func NewMapper(lkrSrc, lkrDst *c.Linker, srcHead, dstHead *n.Commit, srcRoot n.Node) (*Mapper, error) {
var err error
if srcHead == nil {
srcHead, err = lkrSrc.Head()
if err != nil {
return nil, err
}
}
if dstHead == nil {
dstHead, err = lkrDst.Head()
if err != nil {
return nil, err
}
}
return &Mapper{
lkrSrc: lkrSrc,
lkrDst: lkrDst,
srcHead: srcHead,
dstHead: dstHead,
srcRoot: srcRoot,
flagsRoot: trie.NewNodeWithData(&flags{}),
}, nil
}
func (ma *Mapper) nodeIsHandled(nd n.Node, srcToDst bool) bool {
if srcToDst {
return ma.isSrcHandled(nd)
}
return ma.isDstHandled(nd)
}
func (ma *Mapper) isComplete(lkr *c.Linker, root n.Node, srcToDst bool) (bool, error) {
// If the file was already handled: ignore it completely.
if ma.nodeIsHandled(root, srcToDst) {
return false, nil
}
if root.Type() != n.NodeTypeDirectory {
return true, nil
}
dir, ok := root.(*n.Directory)
if !ok {
return false, ie.ErrBadNode
}
children, err := dir.ChildrenSorted(lkr)
if err != nil {
return false, err
}
nComplete := 0
for _, child := range children {
if ma.nodeIsHandled(child, srcToDst) {
continue
}
isComplete, err := ma.isComplete(lkr, child, srcToDst)
if err != nil {
return false, err
}
if isComplete {
nComplete++
}
}
// If all children were not handled & are complete we copy the flag.
if nComplete == len(children) {
if srcToDst {
ma.setSrcComplete(root)
} else {
ma.setDstComplete(root)
}
return true, nil
}
return false, nil
}
// extractLeftovers goes over all nodes in src that were not covered
// yet by previous measures. It will report any src node without a match then.
func (ma *Mapper) extractLeftovers(lkr *c.Linker, root *n.Directory, srcToDst bool) error {
if ma.nodeIsHandled(root, srcToDst) {
return nil
}
if _, err := ma.isComplete(lkr, root, srcToDst); err != nil {
return err
}
// Implement a basic walk/DFS with filtering:
children, err := root.ChildrenSorted(lkr)
if err != nil {
return err
}
for _, child := range children {
debug(fmt.Sprintf("extract: %v", child.Path()))
if ma.nodeIsHandled(child, srcToDst) {
debug(fmt.Sprintf("node is handled: %v", child.Path()))
continue
}
switch child.Type() {
case n.NodeTypeDirectory:
dir, ok := child.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
var complete bool
if srcToDst {
complete = ma.isSrcComplete(dir)
} else {
complete = ma.isDstComplete(dir)
}
debug(fmt.Sprintf("is complete: %v %v", child.Path(), complete))
if complete {
if srcToDst {
err = ma.report(dir, nil, false, false, false)
} else {
err = ma.report(nil, dir, false, false, false)
}
if err != nil {
return err
}
} else {
if err := ma.extractLeftovers(lkr, dir, srcToDst); err != nil {
return err
}
}
case n.NodeTypeFile:
file, ok := child.(*n.File)
if !ok {
return ie.ErrBadNode
}
// Report the leftover:
if srcToDst {
err = ma.report(file, nil, false, false, false)
} else {
err = ma.report(nil, file, false, false, false)
}
if err != nil {
return err
}
case n.NodeTypeGhost:
// Those were already handled (or are not important)
}
}
return nil
}
// Map calls `fn` for each pairing that was found. Equal files and
// directories are not reported. Most directories are also not reported, but
// if they are empty and not present on our side they will. No ghosts will be
// reported.
//
// Some implementation background for the curious reader:
//
// In the simplest case a filesystem is a tree and the assumption can be made
// that one node that lives at the same path on both sides is the same "file"
// (i.e. in terms of "this is the file that the user wants to synchronize with").
//
// With ghosts though, we have nodes that can indicate a removed or a moved file.
// Due to moved files the filesystem tree becomes a graph and the mapping
// algorithm (that is the base of Mapper) needs to do a depth first search
// and thus needs to remember already visited nodes.
//
// Since moved nodes also takes priorty we need to iterate over all ghosts first,
// and mark their respective counterparts or report that they were removed on
// the remote side (i.e. no counterpart exists.). Only after that we cycle
// through all other nodes and assume that files living at the same path
// reference the same "file". At this point we can treat the file graph
// as tree again by ignoring all ghosts.
//
// A special case is when a file was moved on one side but, a file exists
// already on the other side. In this case the already existing files wins.
//
// Some examples of the described behaviours can be found in the tests of Mapper.
func (ma *Mapper) Map(fn func(pair MapPair) error) error {
ma.fn = fn
log.Debugf("mapping ghosts")
if err := ma.handleGhosts(); err != nil {
return err
}
log.Debugf("mapping non-ghosts")
switch ma.srcRoot.Type() {
case n.NodeTypeDirectory:
dir, ok := ma.srcRoot.(*n.Directory)
if !ok {
return ie.ErrBadNode
}
if err := ma.mapDirectory(dir, dir.Path(), false); err != nil {
return err
}
// Get root directories:
// (only get them now since, in theory, mapFn could have changed things)
srcRoot, err := ma.lkrSrc.DirectoryByHash(ma.srcHead.Root())
if err != nil {
return err
}
dstRoot, err := ma.lkrDst.DirectoryByHash(ma.dstHead.Root())
if err != nil {
return err
}
debug("-- Extract leftover src")
// Extract things in "src" that were not mapped yet.
// These are files that can be added to our inventory,
// since we have notthing that mapped to them.
if err := ma.extractLeftovers(ma.lkrSrc, srcRoot, true); err != nil {
return err
}
debug("-- Extract leftover dst")
// Check for files that we have, but dst does not.
// We call those files "missing".
return ma.extractLeftovers(ma.lkrDst, dstRoot, false)
case n.NodeTypeFile:
file, ok := ma.srcRoot.(*n.File)
if !ok {
return ie.ErrBadNode
}
return ma.mapFile(file, file.Path())
case n.NodeTypeGhost:
return nil
default:
return e.Wrapf(ie.ErrBadNode, "Unexpected type in route(): %v", ma.srcRoot)
}
}