From 3b62a6afcc2067ed7f81fe349bcbd13bbbbb5a4a Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 14 Aug 2014 15:06:59 -0300 Subject: [PATCH] Use path.Join(a, b) instead of `a + "/" + b` --- multipartzip/multipartzip.go | 4 ++-- multipartzip/multipartzip_test.go | 5 +++-- repository/repository_test.go | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/multipartzip/multipartzip.go b/multipartzip/multipartzip.go index 540d770..8f32de7 100644 --- a/multipartzip/multipartzip.go +++ b/multipartzip/multipartzip.go @@ -43,7 +43,7 @@ func CopyZipFile(f *zip.File, d, p string) error { if p != "" { dirname := path.Dir(p) if dirname != "." { - err := os.MkdirAll(d+"/"+dirname, 0755) + err := os.MkdirAll(path.Join(d, dirname), 0755) if err != nil { return err } @@ -53,7 +53,7 @@ func CopyZipFile(f *zip.File, d, p string) error { if err != nil { return err } - path := d + "/" + p + path := path.Join(d, p) stat, err := os.Stat(path) if err != nil || !stat.IsDir() { file, err := fs.Filesystem().OpenFile(path, os.O_WRONLY|os.O_CREATE, 0755) diff --git a/multipartzip/multipartzip_test.go b/multipartzip/multipartzip_test.go index 3daed1a..19bdf3c 100644 --- a/multipartzip/multipartzip_test.go +++ b/multipartzip/multipartzip_test.go @@ -12,6 +12,7 @@ import ( "launchpad.net/gocheck" "mime/multipart" "os" + "path" "testing" ) @@ -44,7 +45,7 @@ func (s *S) TestCopyZipFile(c *gocheck.C) { for _, f := range r.File { err = CopyZipFile(f, tempDir, f.Name) c.Assert(err, gocheck.IsNil) - fstat, errStat := os.Stat(tempDir + "/" + f.Name) + fstat, errStat := os.Stat(path.Join(tempDir, f.Name)) c.Assert(errStat, gocheck.IsNil) c.Assert(fstat.IsDir(), gocheck.Equals, false) } @@ -76,7 +77,7 @@ func (s *S) TestExtractZip(c *gocheck.C) { c.Assert(err, gocheck.IsNil) ExtractZip(formfile, tempDir) for _, file := range files { - body, err := ioutil.ReadFile(tempDir + "/" + file.Name) + body, err := ioutil.ReadFile(path.Join(tempDir, file.Name)) c.Assert(err, gocheck.IsNil) c.Assert(string(body), gocheck.Equals, file.Body) } diff --git a/repository/repository_test.go b/repository/repository_test.go index 52e5d89..4bce1ed 100644 --- a/repository/repository_test.go +++ b/repository/repository_test.go @@ -1182,7 +1182,7 @@ func (s *S) TestTempCloneIntegration(c *gocheck.C) { c.Assert(errClone, gocheck.IsNil) dstat, errStat := os.Stat(clone) c.Assert(dstat.IsDir(), gocheck.Equals, true) - fstat, errStat := os.Stat(clone + "/" + file) + fstat, errStat := os.Stat(path.Join(clone, file)) c.Assert(fstat.IsDir(), gocheck.Equals, false) c.Assert(errStat, gocheck.IsNil) } @@ -1219,7 +1219,7 @@ func (s *S) TestTempCloneWhenGitError(c *gocheck.C) { c.Assert(errClone.Error(), gocheck.Equals, expectedErr) dstat, errStat := os.Stat(clone) c.Assert(dstat.IsDir(), gocheck.Equals, true) - fstat, errStat := os.Stat(clone + "/" + file) + fstat, errStat := os.Stat(path.Join(clone, file)) c.Assert(fstat, gocheck.IsNil) c.Assert(errStat, gocheck.NotNil) } @@ -1429,7 +1429,7 @@ func (s *S) TestAddAllIntegration(c *gocheck.C) { defer cloneCleanUp() } c.Assert(errClone, gocheck.IsNil) - errWrite := ioutil.WriteFile(clone+"/"+file, []byte(content+content), 0644) + errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) c.Assert(errWrite, gocheck.IsNil) errWrite = ioutil.WriteFile(clone+"/WOWME", []byte(content+content), 0644) c.Assert(errWrite, gocheck.IsNil) @@ -1494,7 +1494,7 @@ func (s *S) TestCommitIntegration(c *gocheck.C) { defer cloneCleanUp() } c.Assert(errClone, gocheck.IsNil) - errWrite := ioutil.WriteFile(clone+"/"+file, []byte(content+content), 0644) + errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) c.Assert(errWrite, gocheck.IsNil) gitPath, err := exec.LookPath("git") c.Assert(err, gocheck.IsNil) @@ -1582,7 +1582,7 @@ func (s *S) TestPushIntegration(c *gocheck.C) { defer cloneCleanUp() } c.Assert(errClone, gocheck.IsNil) - errWrite := ioutil.WriteFile(clone+"/"+file, []byte(content+content), 0644) + errWrite := ioutil.WriteFile(path.Join(clone, file), []byte(content+content), 0644) c.Assert(errWrite, gocheck.IsNil) errAddAll := AddAll(clone) c.Assert(errAddAll, gocheck.IsNil)