collector: use path/filepath for handling file paths (#1245)

Similar to #1228.  Update the remaining collectors to use
'path/filepath' intead of 'path' for manipulating file paths.

Signed-off-by: Paul Gier <pgier@redhat.com>
This commit is contained in:
Paul Gier 2019-02-05 09:37:27 -06:00 committed by Ben Kochie
commit 2b81bff518
5 changed files with 26 additions and 29 deletions

View file

@ -19,7 +19,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"github.com/prometheus/client_golang/prometheus"
@ -71,21 +71,21 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error {
func readBondingStats(root string) (status map[string][2]int, err error) {
status = map[string][2]int{}
masters, err := ioutil.ReadFile(path.Join(root, "bonding_masters"))
masters, err := ioutil.ReadFile(filepath.Join(root, "bonding_masters"))
if err != nil {
return nil, err
}
for _, master := range strings.Fields(string(masters)) {
slaves, err := ioutil.ReadFile(path.Join(root, master, "bonding", "slaves"))
slaves, err := ioutil.ReadFile(filepath.Join(root, master, "bonding", "slaves"))
if err != nil {
return nil, err
}
sstat := [2]int{0, 0}
for _, slave := range strings.Fields(string(slaves)) {
state, err := ioutil.ReadFile(path.Join(root, master, fmt.Sprintf("lower_%s", slave), "operstate"))
state, err := ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("lower_%s", slave), "operstate"))
if os.IsNotExist(err) {
// some older? kernels use slave_ prefix
state, err = ioutil.ReadFile(path.Join(root, master, fmt.Sprintf("slave_%s", slave), "operstate"))
state, err = ioutil.ReadFile(filepath.Join(root, master, fmt.Sprintf("slave_%s", slave), "operstate"))
}
if err != nil {
return nil, err