-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FilterFS
when skipping lazy parent directories
#183
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,30 @@ file bar/foo | |
`), b.String()) | ||
} | ||
|
||
func TestWalkerIncludeReturnSkipDir(t *testing.T) { | ||
d, err := tmpDir(changeStream([]string{ | ||
"ADD foo dir", | ||
"ADD foo/x dir", | ||
"ADD foo/y dir", | ||
"ADD foo/x/a.txt file", | ||
"ADD foo/y/b.txt file", | ||
})) | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(d) | ||
|
||
found := []string{} | ||
|
||
err = Walk(context.Background(), d, &FilterOpt{ | ||
IncludePatterns: []string{"**/*.txt"}, | ||
}, func(path string, info gofs.FileInfo, err error) error { | ||
found = append(found, path) | ||
return filepath.SkipDir | ||
}) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, []string{"foo"}, found) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would this return anything at all. "foo" does not match the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly that, yup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's not included there then it isn't hooked up to Send/Recv - which means that we don't send the file stats for parent directories. e.g. |
||
} | ||
|
||
func TestWalkerExclude(t *testing.T) { | ||
d, err := tmpDir(changeStream([]string{ | ||
"ADD bar file", | ||
|
@@ -308,6 +332,33 @@ file includeDir/a.txt | |
assert.Equal(t, []string{"excludeDir", "includeDir", filepath.FromSlash("includeDir/a.txt")}, walked) | ||
} | ||
|
||
func TestWalkerMapSkipDirWithPattern(t *testing.T) { | ||
d, err := tmpDir(changeStream([]string{ | ||
"ADD x dir", | ||
"ADD x/a.txt file", | ||
"ADD y dir", | ||
"ADD y/b.txt file", | ||
})) | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(d) | ||
|
||
b := &bytes.Buffer{} | ||
err = Walk(context.Background(), d, &FilterOpt{ | ||
IncludePatterns: []string{"**/*.txt"}, | ||
Map: func(_ string, s *types.Stat) MapResult { | ||
if filepath.Base(s.Path) == "x" { | ||
return MapResultSkipDir | ||
} | ||
return MapResultKeep | ||
}, | ||
}, bufWalk(b)) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, filepath.FromSlash(`dir y | ||
file y/b.txt | ||
`), b.String()) | ||
} | ||
|
||
func TestWalkerPermissionDenied(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip("os.Chmod not fully supported on Windows") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: don't need
else if
after acontinue
.