Skip to content

Commit

Permalink
Consistently use filepath package (#292)
Browse files Browse the repository at this point in the history
Usage of filepath vs. path seems to have been pretty random.
With this change, we consistently use filepath which considers
the platform-specific path separator.

Signed-off-by: Reinhard Nägele <[email protected]>
  • Loading branch information
unguiculus authored Nov 2, 2020
1 parent 2407e7d commit fd6720b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package config
import (
"fmt"
"os"
"path"
"path/filepath"
"reflect"
"strings"

Expand All @@ -34,7 +34,7 @@ var (
homeDir, _ = homedir.Dir()
configSearchLocations = []string{
".",
path.Join(homeDir, ".ct"),
filepath.Join(homeDir, ".ct"),
"/usr/local/etc/ct",
"/etc/ct",
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func printCfg(cfg *Configuration) {

func findConfigFile(fileName string) (string, error) {
for _, location := range configSearchLocations {
filePath := path.Join(location, fileName)
filePath := filepath.Join(location, fileName)
if util.FileExists(filePath) {
return filePath, nil
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"math/rand"
"net"
"os"
"path"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -115,7 +114,7 @@ func (l DirectoryLister) ListChildDirs(parentDir string, test func(dir string) b
var dirs []string
for _, dir := range fileInfos {
dirName := dir.Name()
parentSlashChildDir := path.Join(parentDir, dirName)
parentSlashChildDir := filepath.Join(parentDir, dirName)
if test(parentSlashChildDir) {
dirs = append(dirs, parentSlashChildDir)
}
Expand All @@ -130,8 +129,8 @@ func (u ChartUtils) LookupChartDir(chartDirs []string, dir string) (string, erro
for _, chartDir := range chartDirs {
currentDir := dir
for {
chartYaml := path.Join(currentDir, "Chart.yaml")
parent := path.Dir(path.Dir(chartYaml))
chartYaml := filepath.Join(currentDir, "Chart.yaml")
parent := filepath.Dir(filepath.Dir(chartYaml))
chartDir = strings.TrimRight(chartDir, "/") // remove any trailing slash from the dir

// check directory has a Chart.yaml and that it is in a
Expand All @@ -140,9 +139,9 @@ func (u ChartUtils) LookupChartDir(chartDirs []string, dir string) (string, erro
return currentDir, nil
}

currentDir = path.Dir(currentDir)
currentDir = filepath.Dir(currentDir)
relativeDir, _ := filepath.Rel(chartDir, currentDir)
joined := path.Join(chartDir, relativeDir)
joined := filepath.Join(chartDir, relativeDir)
if (joined == chartDir) || strings.HasPrefix(relativeDir, "..") {
break
}
Expand All @@ -155,7 +154,7 @@ func (u ChartUtils) LookupChartDir(chartDirs []string, dir string) (string, erro
// and return a newly allocated ChartYaml object. If no Chart.yaml is present
// or there is an error unmarshaling the file contents, an error will be returned.
func ReadChartYaml(dir string) (*ChartYaml, error) {
yamlBytes, err := ioutil.ReadFile(path.Join(dir, "Chart.yaml"))
yamlBytes, err := ioutil.ReadFile(filepath.Join(dir, "Chart.yaml"))
if err != nil {
return nil, errors.Wrap(err, "Could not read 'Chart.yaml'")
}
Expand Down

0 comments on commit fd6720b

Please sign in to comment.