lib/scanner: Refactor scanner.Walk API
The old usage pattern was to create a Walker with a bunch of attributes, then call Walk() on it and nothing else. This extracts the attributes into a Config struct and exposes a Walk(cfg Config) method instead, as there was no reason to expose the state-holding walker type. Also creates a few no-op implementations of the necessary interfaces so that we can skip nil checks and simiplify things here and there. Definitely look at this diff without whitespace. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3060
This commit is contained in:
committed by
Audrius Butkevicius
parent
d77d8ff803
commit
21e116aa45
@@ -59,14 +59,13 @@ func TestWalkSub(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
w := Walker{
|
||||
fchan, err := Walk(Config{
|
||||
Dir: "testdata",
|
||||
Subs: []string{"dir2"},
|
||||
BlockSize: 128 * 1024,
|
||||
Matcher: ignores,
|
||||
Hashers: 2,
|
||||
}
|
||||
fchan, err := w.Walk()
|
||||
})
|
||||
var files []protocol.FileInfo
|
||||
for f := range fchan {
|
||||
files = append(files, f)
|
||||
@@ -97,14 +96,13 @@ func TestWalk(t *testing.T) {
|
||||
}
|
||||
t.Log(ignores)
|
||||
|
||||
w := Walker{
|
||||
fchan, err := Walk(Config{
|
||||
Dir: "testdata",
|
||||
BlockSize: 128 * 1024,
|
||||
Matcher: ignores,
|
||||
Hashers: 2,
|
||||
}
|
||||
})
|
||||
|
||||
fchan, err := w.Walk()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -122,22 +120,20 @@ func TestWalk(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWalkError(t *testing.T) {
|
||||
w := Walker{
|
||||
_, err := Walk(Config{
|
||||
Dir: "testdata-missing",
|
||||
BlockSize: 128 * 1024,
|
||||
Hashers: 2,
|
||||
}
|
||||
_, err := w.Walk()
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Error("no error from missing directory")
|
||||
}
|
||||
|
||||
w = Walker{
|
||||
_, err = Walk(Config{
|
||||
Dir: "testdata/bar",
|
||||
BlockSize: 128 * 1024,
|
||||
}
|
||||
_, err = w.Walk()
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Error("no error from non-directory")
|
||||
@@ -278,7 +274,7 @@ func TestNormalization(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssue1507(t *testing.T) {
|
||||
w := Walker{}
|
||||
w := &walker{}
|
||||
c := make(chan protocol.FileInfo, 100)
|
||||
fn := w.walkAndHashFiles(c, c)
|
||||
|
||||
@@ -286,14 +282,13 @@ func TestIssue1507(t *testing.T) {
|
||||
}
|
||||
|
||||
func walkDir(dir string) ([]protocol.FileInfo, error) {
|
||||
w := Walker{
|
||||
fchan, err := Walk(Config{
|
||||
Dir: dir,
|
||||
BlockSize: 128 * 1024,
|
||||
AutoNormalize: true,
|
||||
Hashers: 2,
|
||||
}
|
||||
})
|
||||
|
||||
fchan, err := w.Walk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user