From 49beccf7726887211cfb05a20f6bbc175ec5847e Mon Sep 17 00:00:00 2001 From: Derek Richard and Tyler Schultz Date: Mon, 29 Sep 2014 16:32:41 -0700 Subject: [PATCH] Use filepath instead of path where possible -Path does not always work well with windows [#79748230] --- cf/api/buildpack_bits.go | 2 +- cf/app_files/cf_ignore.go | 14 +++++++------- cf/commands/plugin/install_plugin.go | 14 +++++++------- cf/commands/plugin/install_plugin_test.go | 22 +++++++++++----------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cf/api/buildpack_bits.go b/cf/api/buildpack_bits.go index 729f1a8bee6..22472209815 100644 --- a/cf/api/buildpack_bits.go +++ b/cf/api/buildpack_bits.go @@ -160,7 +160,7 @@ func findBuildpackPath(zipFiles []*zip.File) (parentPath string, foundBuildpack for _, file := range zipFiles { if strings.HasSuffix(file.Name, needle) { foundBuildpack = true - parentPath = path.Join(file.Name, "..", "..") + parentPath = filepath.Join(file.Name, "..", "..") if parentPath == "." { parentPath = "" } diff --git a/cf/app_files/cf_ignore.go b/cf/app_files/cf_ignore.go index e328c35e1fe..297f65a2a7c 100644 --- a/cf/app_files/cf_ignore.go +++ b/cf/app_files/cf_ignore.go @@ -1,7 +1,7 @@ package app_files import ( - "path" + "path/filepath" "strings" "github.com/cloudfoundry/cli/glob" @@ -28,7 +28,7 @@ func NewCfIgnore(text string) CfIgnore { ignore = false } - for _, p := range globsForPattern(path.Clean(line)) { + for _, p := range globsForPattern(filepath.Clean(line)) { patterns = append(patterns, ignorePattern{ignore, p}) } } @@ -54,13 +54,13 @@ func (ignore cfIgnore) FileShouldBeIgnored(path string) bool { func globsForPattern(pattern string) (globs []glob.Glob) { globs = append(globs, glob.MustCompileGlob(pattern)) - globs = append(globs, glob.MustCompileGlob(path.Join(pattern, "*"))) - globs = append(globs, glob.MustCompileGlob(path.Join(pattern, "**", "*"))) + globs = append(globs, glob.MustCompileGlob(filepath.Join(pattern, "*"))) + globs = append(globs, glob.MustCompileGlob(filepath.Join(pattern, "**", "*"))) if !strings.HasPrefix(pattern, "/") { - globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern))) - globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern, "*"))) - globs = append(globs, glob.MustCompileGlob(path.Join("**", pattern, "**", "*"))) + globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern))) + globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern, "*"))) + globs = append(globs, glob.MustCompileGlob(filepath.Join("**", pattern, "**", "*"))) } return diff --git a/cf/commands/plugin/install_plugin.go b/cf/commands/plugin/install_plugin.go index 722972f047a..c0de9044195 100644 --- a/cf/commands/plugin/install_plugin.go +++ b/cf/commands/plugin/install_plugin.go @@ -3,7 +3,7 @@ package plugin import ( "fmt" "os" - "path" + "path/filepath" "github.com/cloudfoundry/cli/cf/command_metadata" "github.com/cloudfoundry/cli/cf/configuration" @@ -45,7 +45,7 @@ func (cmd *PluginInstall) GetRequirements(_ requirements.Factory, c *cli.Context func (cmd *PluginInstall) Run(c *cli.Context) { pluginPath := c.Args()[0] - _, pluginName := path.Split(pluginPath) + _, pluginName := filepath.Split(pluginPath) plugins := cmd.config.Plugins() @@ -55,27 +55,27 @@ func (cmd *PluginInstall) Run(c *cli.Context) { cmd.ui.Say(fmt.Sprintf(T("Installing plugin {{.PluginName}}...", map[string]interface{}{"PluginName": pluginName}))) - homeDir := path.Join(cmd.config.UserHomePath(), ".cf", "plugin") + homeDir := filepath.Join(cmd.config.UserHomePath(), ".cf", "plugin") err := os.MkdirAll(homeDir, 0700) if err != nil { cmd.ui.Failed(fmt.Sprintf(T("Could not create the plugin directory: \n{{.Error}}", map[string]interface{}{"Error": err.Error()}))) } - _, err = os.Stat(path.Join(homeDir, pluginName)) + _, err = os.Stat(filepath.Join(homeDir, pluginName)) if err == nil || os.IsExist(err) { cmd.ui.Failed(fmt.Sprintf(T("The file {{.PluginName}} already exists under the plugin directory.\n", map[string]interface{}{"PluginName": pluginName}))) } else if !os.IsNotExist(err) { cmd.ui.Failed(fmt.Sprintf(T("Unexpected error has occurred:\n{{.Error}}", map[string]interface{}{"Error": err.Error()}))) } - err = fileutils.CopyFile(path.Join(homeDir, pluginName), pluginPath) + err = fileutils.CopyFile(filepath.Join(homeDir, pluginName), pluginPath) if err != nil { cmd.ui.Failed(fmt.Sprintf(T("Could not copy plugin binary: \n{{.Error}}", map[string]interface{}{"Error": err.Error()}))) } - os.Chmod(path.Join(homeDir, pluginName), 0700) + os.Chmod(filepath.Join(homeDir, pluginName), 0700) - cmd.config.SetPlugin(pluginName, path.Join(homeDir, pluginName)) + cmd.config.SetPlugin(pluginName, filepath.Join(homeDir, pluginName)) cmd.ui.Ok() cmd.ui.Say(fmt.Sprintf(T("Plugin {{.PluginName}} successfully installed.", map[string]interface{}{"PluginName": pluginName}))) diff --git a/cf/commands/plugin/install_plugin_test.go b/cf/commands/plugin/install_plugin_test.go index f9f76784af4..16cbc0f32ca 100644 --- a/cf/commands/plugin/install_plugin_test.go +++ b/cf/commands/plugin/install_plugin_test.go @@ -3,7 +3,7 @@ package plugin_test import ( "io/ioutil" "os" - "path" + "path/filepath" "runtime" testconfig "github.com/cloudfoundry/cli/cf/configuration/fakes" @@ -45,7 +45,7 @@ var _ = Describe("Install", func() { var err error homeDir, err = ioutil.TempDir(os.TempDir(), "plugin") Expect(err).ToNot(HaveOccurred()) - pluginDir = path.Join(homeDir, ".cf", "plugin") + pluginDir = filepath.Join(homeDir, ".cf", "plugin") curDir, err = os.Getwd() Expect(err).ToNot(HaveOccurred()) @@ -79,15 +79,15 @@ var _ = Describe("Install", func() { }) AfterEach(func() { - os.Remove(path.Join(curDir, pluginFile.Name())) + os.Remove(filepath.Join(curDir, pluginFile.Name())) os.Remove(homeDir) }) It("if a file with the plugin name already exists under ~/.cf/plugin/", func() { - err := fileutils.CopyFile(path.Join(pluginDir, pluginFile.Name()), path.Join(curDir, pluginFile.Name())) + err := fileutils.CopyFile(filepath.Join(pluginDir, pluginFile.Name()), filepath.Join(curDir, pluginFile.Name())) Expect(err).NotTo(HaveOccurred()) - runCommand(path.Join(curDir, pluginFile.Name())) + runCommand(filepath.Join(curDir, pluginFile.Name())) Expect(ui.Outputs).To(ContainSubstrings( []string{"Installing plugin"}, []string{"The file", pluginFile.Name(), "already exists"}, @@ -101,24 +101,24 @@ var _ = Describe("Install", func() { BeforeEach(func() { setupTempExecutable() config.UserHomePathReturns(homeDir) - runCommand(path.Join(curDir, pluginFile.Name())) + runCommand(filepath.Join(curDir, pluginFile.Name())) }) AfterEach(func() { - os.Remove(path.Join(curDir, pluginFile.Name())) + os.Remove(filepath.Join(curDir, pluginFile.Name())) os.Remove(homeDir) }) It("copies the plugin into directory ~/.cf/plugin/PLUGIN_NAME", func() { - _, err := os.Stat(path.Join(curDir, pluginFile.Name())) + _, err := os.Stat(filepath.Join(curDir, pluginFile.Name())) Expect(err).ToNot(HaveOccurred()) - _, err = os.Stat(path.Join(pluginDir, pluginFile.Name())) + _, err = os.Stat(filepath.Join(pluginDir, pluginFile.Name())) Expect(err).ToNot(HaveOccurred()) }) if runtime.GOOS != "windows" { It("Chmods the plugin so it is executable", func() { - fileInfo, err := os.Stat(path.Join(pluginDir, pluginFile.Name())) + fileInfo, err := os.Stat(filepath.Join(pluginDir, pluginFile.Name())) Expect(err).ToNot(HaveOccurred()) Expect(int(fileInfo.Mode())).To(Equal(0700)) }) @@ -127,7 +127,7 @@ var _ = Describe("Install", func() { It("populate the configuration map with the plugin name and location", func() { pluginName, pluginPath := config.SetPluginArgsForCall(0) Expect(pluginName).To(Equal(pluginFile.Name())) - Expect(pluginPath).To(Equal(path.Join(pluginDir, pluginFile.Name()))) + Expect(pluginPath).To(Equal(filepath.Join(pluginDir, pluginFile.Name()))) Expect(ui.Outputs).To(ContainSubstrings( []string{"Installing plugin", pluginFile.Name()}, []string{"OK"},