Prevent panic if fileinfo is nil (#4850)

This commit is contained in:
Greg 2018-10-12 15:43:06 -06:00 committed by Daniel Nelson
parent d3078ec9d8
commit 9cc534c624
1 changed files with 6 additions and 0 deletions

View File

@ -139,6 +139,12 @@ func absDuration(x time.Duration) time.Duration {
func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, recursive bool) { func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, recursive bool) {
numFiles := int64(0) numFiles := int64(0)
walkFn := func(path string, file os.FileInfo, err error) error { walkFn := func(path string, file os.FileInfo, err error) error {
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
if path == basedir { if path == basedir {
return nil return nil
} }