Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use filepath package #292

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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