Skip to content

Commit 49beccf

Browse files
committed
Use filepath instead of path where possible
-Path does not always work well with windows [#79748230]
1 parent a45acff commit 49beccf

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

cf/api/buildpack_bits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func findBuildpackPath(zipFiles []*zip.File) (parentPath string, foundBuildpack
160160
for _, file := range zipFiles {
161161
if strings.HasSuffix(file.Name, needle) {
162162
foundBuildpack = true
163-
parentPath = path.Join(file.Name, "..", "..")
163+
parentPath = filepath.Join(file.Name, "..", "..")
164164
if parentPath == "." {
165165
parentPath = ""
166166
}

cf/app_files/cf_ignore.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package app_files
22

33
import (
4-
"path"
4+
"path/filepath"
55
"strings"
66

77
"github.com/cloudfoundry/cli/glob"
@@ -28,7 +28,7 @@ func NewCfIgnore(text string) CfIgnore {
2828
ignore = false
2929
}
3030

31-
for _, p := range globsForPattern(path.Clean(line)) {
31+
for _, p := range globsForPattern(filepath.Clean(line)) {
3232
patterns = append(patterns, ignorePattern{ignore, p})
3333
}
3434
}
@@ -54,13 +54,13 @@ func (ignore cfIgnore) FileShouldBeIgnored(path string) bool {
5454

5555
func globsForPattern(pattern string) (globs []glob.Glob) {
5656
globs = append(globs, glob.MustCompileGlob(pattern))
57-
globs = append(globs, glob.MustCompileGlob(path.Join(pattern, "*")))
58-
globs = append(globs, glob.MustCompileGlob(path.Join(pattern, "**", "*")))
57+
globs = append(globs, glob.MustCompileGlob(filepath.Join(pattern, "*")))
58+
globs = append(globs, glob.MustCompileGlob(filepath.Join(pattern, "**", "*")))
5959

6060
if !strings.HasPrefix(pattern, "/") {
61-
globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern)))
62-
globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern, "*")))
63-
globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern, "**", "*")))
61+
globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern)))
62+
globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern, "*")))
63+
globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern, "**", "*")))
6464
}
6565

6666
return

cf/commands/plugin/install_plugin.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package plugin
33
import (
44
"fmt"
55
"os"
6-
"path"
6+
"path/filepath"
77

88
"github.com/cloudfoundry/cli/cf/command_metadata"
99
"github.com/cloudfoundry/cli/cf/configuration"
@@ -45,7 +45,7 @@ func (cmd *PluginInstall) GetRequirements(_ requirements.Factory, c *cli.Context
4545
func (cmd *PluginInstall) Run(c *cli.Context) {
4646
pluginPath := c.Args()[0]
4747

48-
_, pluginName := path.Split(pluginPath)
48+
_, pluginName := filepath.Split(pluginPath)
4949

5050
plugins := cmd.config.Plugins()
5151

@@ -55,27 +55,27 @@ func (cmd *PluginInstall) Run(c *cli.Context) {
5555

5656
cmd.ui.Say(fmt.Sprintf(T("Installing plugin {{.PluginName}}...", map[string]interface{}{"PluginName": pluginName})))
5757

58-
homeDir := path.Join(cmd.config.UserHomePath(), ".cf", "plugin")
58+
homeDir := filepath.Join(cmd.config.UserHomePath(), ".cf", "plugin")
5959
err := os.MkdirAll(homeDir, 0700)
6060
if err != nil {
6161
cmd.ui.Failed(fmt.Sprintf(T("Could not create the plugin directory: \n{{.Error}}", map[string]interface{}{"Error": err.Error()})))
6262
}
6363

64-
_, err = os.Stat(path.Join(homeDir, pluginName))
64+
_, err = os.Stat(filepath.Join(homeDir, pluginName))
6565
if err == nil || os.IsExist(err) {
6666
cmd.ui.Failed(fmt.Sprintf(T("The file {{.PluginName}} already exists under the plugin directory.\n", map[string]interface{}{"PluginName": pluginName})))
6767
} else if !os.IsNotExist(err) {
6868
cmd.ui.Failed(fmt.Sprintf(T("Unexpected error has occurred:\n{{.Error}}", map[string]interface{}{"Error": err.Error()})))
6969
}
7070

71-
err = fileutils.CopyFile(path.Join(homeDir, pluginName), pluginPath)
71+
err = fileutils.CopyFile(filepath.Join(homeDir, pluginName), pluginPath)
7272
if err != nil {
7373
cmd.ui.Failed(fmt.Sprintf(T("Could not copy plugin binary: \n{{.Error}}", map[string]interface{}{"Error": err.Error()})))
7474
}
7575

76-
os.Chmod(path.Join(homeDir, pluginName), 0700)
76+
os.Chmod(filepath.Join(homeDir, pluginName), 0700)
7777

78-
cmd.config.SetPlugin(pluginName, path.Join(homeDir, pluginName))
78+
cmd.config.SetPlugin(pluginName, filepath.Join(homeDir, pluginName))
7979

8080
cmd.ui.Ok()
8181
cmd.ui.Say(fmt.Sprintf(T("Plugin {{.PluginName}} successfully installed.", map[string]interface{}{"PluginName": pluginName})))

cf/commands/plugin/install_plugin_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package plugin_test
33
import (
44
"io/ioutil"
55
"os"
6-
"path"
6+
"path/filepath"
77
"runtime"
88

99
testconfig "github.com/cloudfoundry/cli/cf/configuration/fakes"
@@ -45,7 +45,7 @@ var _ = Describe("Install", func() {
4545
var err error
4646
homeDir, err = ioutil.TempDir(os.TempDir(), "plugin")
4747
Expect(err).ToNot(HaveOccurred())
48-
pluginDir = path.Join(homeDir, ".cf", "plugin")
48+
pluginDir = filepath.Join(homeDir, ".cf", "plugin")
4949

5050
curDir, err = os.Getwd()
5151
Expect(err).ToNot(HaveOccurred())
@@ -79,15 +79,15 @@ var _ = Describe("Install", func() {
7979
})
8080

8181
AfterEach(func() {
82-
os.Remove(path.Join(curDir, pluginFile.Name()))
82+
os.Remove(filepath.Join(curDir, pluginFile.Name()))
8383
os.Remove(homeDir)
8484
})
8585

8686
It("if a file with the plugin name already exists under ~/.cf/plugin/", func() {
87-
err := fileutils.CopyFile(path.Join(pluginDir, pluginFile.Name()), path.Join(curDir, pluginFile.Name()))
87+
err := fileutils.CopyFile(filepath.Join(pluginDir, pluginFile.Name()), filepath.Join(curDir, pluginFile.Name()))
8888
Expect(err).NotTo(HaveOccurred())
8989

90-
runCommand(path.Join(curDir, pluginFile.Name()))
90+
runCommand(filepath.Join(curDir, pluginFile.Name()))
9191
Expect(ui.Outputs).To(ContainSubstrings(
9292
[]string{"Installing plugin"},
9393
[]string{"The file", pluginFile.Name(), "already exists"},
@@ -101,24 +101,24 @@ var _ = Describe("Install", func() {
101101
BeforeEach(func() {
102102
setupTempExecutable()
103103
config.UserHomePathReturns(homeDir)
104-
runCommand(path.Join(curDir, pluginFile.Name()))
104+
runCommand(filepath.Join(curDir, pluginFile.Name()))
105105
})
106106

107107
AfterEach(func() {
108-
os.Remove(path.Join(curDir, pluginFile.Name()))
108+
os.Remove(filepath.Join(curDir, pluginFile.Name()))
109109
os.Remove(homeDir)
110110
})
111111

112112
It("copies the plugin into directory ~/.cf/plugin/PLUGIN_NAME", func() {
113-
_, err := os.Stat(path.Join(curDir, pluginFile.Name()))
113+
_, err := os.Stat(filepath.Join(curDir, pluginFile.Name()))
114114
Expect(err).ToNot(HaveOccurred())
115-
_, err = os.Stat(path.Join(pluginDir, pluginFile.Name()))
115+
_, err = os.Stat(filepath.Join(pluginDir, pluginFile.Name()))
116116
Expect(err).ToNot(HaveOccurred())
117117
})
118118

119119
if runtime.GOOS != "windows" {
120120
It("Chmods the plugin so it is executable", func() {
121-
fileInfo, err := os.Stat(path.Join(pluginDir, pluginFile.Name()))
121+
fileInfo, err := os.Stat(filepath.Join(pluginDir, pluginFile.Name()))
122122
Expect(err).ToNot(HaveOccurred())
123123
Expect(int(fileInfo.Mode())).To(Equal(0700))
124124
})
@@ -127,7 +127,7 @@ var _ = Describe("Install", func() {
127127
It("populate the configuration map with the plugin name and location", func() {
128128
pluginName, pluginPath := config.SetPluginArgsForCall(0)
129129
Expect(pluginName).To(Equal(pluginFile.Name()))
130-
Expect(pluginPath).To(Equal(path.Join(pluginDir, pluginFile.Name())))
130+
Expect(pluginPath).To(Equal(filepath.Join(pluginDir, pluginFile.Name())))
131131
Expect(ui.Outputs).To(ContainSubstrings(
132132
[]string{"Installing plugin", pluginFile.Name()},
133133
[]string{"OK"},

0 commit comments

Comments
 (0)