From 93c8343c2a83e0d105e481c43b939504ec2bafff Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Sat, 12 Oct 2024 11:41:41 +0100 Subject: [PATCH] feat: simplify stats recording in filesystem reader Signed-off-by: Brian McGee --- walk/filesystem.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/walk/filesystem.go b/walk/filesystem.go index b27afb5f..dc536e50 100644 --- a/walk/filesystem.go +++ b/walk/filesystem.go @@ -80,6 +80,11 @@ func (f *FilesystemReader) process() error { // Read populates the provided files array with as many files are available until the provided context is cancelled. // You must ensure to pass a context with a timeout otherwise this will block until files is full. func (f *FilesystemReader) Read(ctx context.Context, files []*File) (n int, err error) { + // ensure we record how many files we traversed + defer func() { + f.stats.Add(stats.Traversed, int32(n)) + }() + idx := 0 LOOP: @@ -102,9 +107,6 @@ LOOP: // set the next file entry files[idx] = file idx++ - - // record that we traversed a file - f.stats.Add(stats.Traversed, 1) } }