Skip to content

Commit

Permalink
Fix basedir check and parent dir extraction in filecount input (influ…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and bitcharmer committed Oct 18, 2019
1 parent 857d4c2 commit 2a3d274
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions plugins/inputs/filecount/filecount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"log"
"os"
"path/filepath"
"strings"
"time"

"github.com/karrick/godirwalk"
"github.com/pkg/errors"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/internal/globpath"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/karrick/godirwalk"
"github.com/pkg/errors"
)

const sampleConfig = `
Expand Down Expand Up @@ -157,7 +155,8 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
childSize := make(map[string]int64)

walkFn := func(path string, de *godirwalk.Dirent) error {
if path == basedir {
rel, err := filepath.Rel(basedir, path)
if err == nil && rel == "." {
return nil
}
file, err := os.Stat(path)
Expand All @@ -173,7 +172,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
return nil
}
if match {
parent := path[:strings.LastIndex(path, "/")]
parent := filepath.Dir(path)
childCount[parent]++
childSize[parent] += file.Size()
}
Expand All @@ -194,7 +193,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
"directory": path,
})
}
parent := path[:strings.LastIndex(path, "/")]
parent := filepath.Dir(path)
if fc.Recursive {
childCount[parent] += childCount[path]
childSize[parent] += childSize[path]
Expand Down

0 comments on commit 2a3d274

Please sign in to comment.