From 65986b345f9e8ecf7e75f58fc1b2936a397e9520 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Mon, 11 May 2020 02:34:19 -0400 Subject: ignoring hidden directories in user count, changed error message to specify it came from user count query --- usercount.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/usercount.go b/usercount.go index 180c573..37b8697 100644 --- a/usercount.go +++ b/usercount.go @@ -11,10 +11,18 @@ import ( func userCountQuery(format string) ([]byte, error) { ls, err := exec.Command("/bin/ls", "/home").Output() if err != nil { - return nil, fmt.Errorf("Couldn't execute ls: %w", err) + return nil, fmt.Errorf("User Count Query: %w", err) } split := strings.Fields(string(ls)) + total := 0 + + for _, e := range split { + if strings.HasPrefix(e, ".") || strings.HasPrefix(e, "_") { + continue + } + total++ + } if format == "plain" { return []byte(fmt.Sprintf("%v users\n", len(split))), nil @@ -23,7 +31,7 @@ func userCountQuery(format string) ([]byte, error) { out := fmt.Sprintf(`{ "userCount": "%v" } -`, len(split)) +`, total) return []byte(out), nil } -- cgit 1.4.1-2-gfad0