@@ -22,9 +22,11 @@ package cmd
22
22
23
23
import (
24
24
"context"
25
+ "github.com/Azure/azure-pipeline-go/pipeline"
25
26
"io"
26
27
"os"
27
28
"path/filepath"
29
+ "runtime"
28
30
"strings"
29
31
"time"
30
32
@@ -55,6 +57,66 @@ func trySymlink(src, dst string, c *chk.C) {
55
57
}
56
58
}
57
59
60
+ func (s * genericTraverserSuite ) TestLocalWildcardOverlap (c * chk.C ) {
61
+ if runtime .GOOS == "windows" {
62
+ c .Skip ("invalid filename used" )
63
+ return
64
+ }
65
+
66
+ /*
67
+ Wildcard support is not actually a part of the local traverser, believe it or not.
68
+ It's instead implemented in InitResourceTraverser as a short-circuit to a list traverser
69
+ utilizing the filepath.Glob function, which then initializes local traversers to achieve the same effect.
70
+ */
71
+ tmpDir := scenarioHelper {}.generateLocalDirectory (c )
72
+ defer func (path string ) { _ = os .RemoveAll (path ) }(tmpDir )
73
+
74
+ scenarioHelper {}.generateLocalFilesFromList (c , tmpDir , []string {
75
+ "test.txt" ,
76
+ "tes*t.txt" ,
77
+ "foobarbaz/test.txt" ,
78
+ })
79
+
80
+ resource , err := SplitResourceString (filepath .Join (tmpDir , "tes*t.txt" ), common .ELocation .Local ())
81
+ c .Assert (err , chk .IsNil )
82
+
83
+ traverser , err := InitResourceTraverser (
84
+ resource ,
85
+ common .ELocation .Local (),
86
+ nil ,
87
+ nil ,
88
+ common .ESymlinkHandlingType .Follow (),
89
+ nil ,
90
+ true ,
91
+ false ,
92
+ false ,
93
+ common .EPermanentDeleteOption .None (),
94
+ nil ,
95
+ nil ,
96
+ false ,
97
+ common .ESyncHashType .None (),
98
+ common .EPreservePermissionsOption .None (),
99
+ pipeline .LogInfo ,
100
+ common.CpkOptions {},
101
+ nil ,
102
+ true ,
103
+ )
104
+ c .Assert (err , chk .IsNil )
105
+
106
+ seenFiles := make (map [string ]bool )
107
+
108
+ err = traverser .Traverse (nil , func (storedObject StoredObject ) error {
109
+ seenFiles [storedObject .relativePath ] = true
110
+ return nil
111
+ }, []ObjectFilter {})
112
+ c .Assert (err , chk .IsNil )
113
+
114
+ c .Assert (seenFiles , chk .DeepEquals , map [string ]bool {
115
+ "test.txt" : true ,
116
+ "tes*t.txt" : true ,
117
+ })
118
+ }
119
+
58
120
// GetProperties tests.
59
121
// GetProperties does not exist on Blob, as the properties come in the list call.
60
122
// While BlobFS could get properties in the future, it's currently disabled as BFS source S2S isn't set up right now, and likely won't be.
@@ -483,7 +545,7 @@ func (s *genericTraverserSuite) TestTraverserWithSingleObject(c *chk.C) {
483
545
scenarioHelper {}.generateLocalFilesFromList (c , dstDirName , blobList )
484
546
485
547
// construct a local traverser
486
- localTraverser := newLocalTraverser (context .TODO (), filepath .Join (dstDirName , dstFileName ), false , common .ESymlinkHandlingType .Skip (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
548
+ localTraverser := newLocalTraverser (context .TODO (), filepath .Join (dstDirName , dstFileName ), false , false , common .ESymlinkHandlingType .Follow (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
487
549
488
550
// invoke the local traversal with a dummy processor
489
551
localDummyProcessor := dummyProcessor {}
@@ -643,7 +705,7 @@ func (s *genericTraverserSuite) TestTraverserContainerAndLocalDirectory(c *chk.C
643
705
// test two scenarios, either recursive or not
644
706
for _ , isRecursiveOn := range []bool {true , false } {
645
707
// construct a local traverser
646
- localTraverser := newLocalTraverser (context .TODO (), dstDirName , isRecursiveOn , common .ESymlinkHandlingType .Skip (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
708
+ localTraverser := newLocalTraverser (context .TODO (), dstDirName , isRecursiveOn , false , common .ESymlinkHandlingType .Follow (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
647
709
648
710
// invoke the local traversal with an indexer
649
711
// so that the results are indexed for easy validation
@@ -804,7 +866,7 @@ func (s *genericTraverserSuite) TestTraverserWithVirtualAndLocalDirectory(c *chk
804
866
// test two scenarios, either recursive or not
805
867
for _ , isRecursiveOn := range []bool {true , false } {
806
868
// construct a local traverser
807
- localTraverser := newLocalTraverser (context .TODO (), filepath .Join (dstDirName , virDirName ), isRecursiveOn , common .ESymlinkHandlingType .Skip (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
869
+ localTraverser := newLocalTraverser (context .TODO (), filepath .Join (dstDirName , virDirName ), isRecursiveOn , false , common .ESymlinkHandlingType .Follow (), common .ESyncHashType .None (), func (common.EntityType ) {}, nil )
808
870
809
871
// invoke the local traversal with an indexer
810
872
// so that the results are indexed for easy validation
0 commit comments