summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/filecheck/collect.go
blob: 921846a7581a148b45bf0104d686284c7ec0bd2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: GPL-3.0-or-later

package filecheck

import (
	"regexp"
	"runtime"
	"strings"
)

func (fc *Filecheck) collect() (map[string]int64, error) {
	ms := make(map[string]int64)

	fc.collectFiles(ms)
	fc.collectDirs(ms)

	return ms, nil
}

func hasMeta(path string) bool {
	magicChars := `*?[`
	if runtime.GOOS != "windows" {
		magicChars = `*?[\`
	}
	return strings.ContainsAny(path, magicChars)
}

func removeDuplicates(s []string) []string {
	set := make(map[string]bool, len(s))
	uniq := s[:0]
	for _, v := range s {
		if !set[v] {
			set[v] = true
			uniq = append(uniq, v)
		}
	}
	return uniq
}

var reSpace = regexp.MustCompile(`\s`)