From ab7db078367dd77b6e70bbb282e02f4efd85bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sun, 13 Jul 2025 02:01:44 +0200 Subject: [PATCH] filetime: support windows paths (#2118) --- internal/collector/filetime/filetime.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/collector/filetime/filetime.go b/internal/collector/filetime/filetime.go index 0dbdd2fe..e80b6ed1 100644 --- a/internal/collector/filetime/filetime.go +++ b/internal/collector/filetime/filetime.go @@ -19,6 +19,7 @@ package filetime import ( "fmt" + "io/fs" "log/slog" "os" "path/filepath" @@ -139,16 +140,11 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { } func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern string) error { - basePath, pattern := doublestar.SplitPattern(filePattern) + basePath, pattern := doublestar.SplitPattern(filepath.ToSlash(filePattern)) basePathFS := os.DirFS(basePath) - matches, err := doublestar.Glob(basePathFS, pattern, doublestar.WithFilesOnly(), doublestar.WithCaseInsensitive()) - if err != nil { - return fmt.Errorf("failed to glob: %w", err) - } - - for _, match := range matches { - filePath := filepath.Join(basePath, match) + err := doublestar.GlobWalk(basePathFS, pattern, func(path string, d fs.DirEntry) error { + filePath := filepath.Join(basePath, path) fileInfo, err := os.Stat(filePath) if err != nil { @@ -157,7 +153,7 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern slog.Any("err", err), ) - continue + return nil } ch <- prometheus.MustNewConstMetric( @@ -166,6 +162,11 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern float64(fileInfo.ModTime().UTC().UnixMicro())/1e6, filePath, ) + + return nil + }, doublestar.WithFilesOnly(), doublestar.WithCaseInsensitive()) + if err != nil { + return fmt.Errorf("failed to glob: %w", err) } return nil