temporal: fix TempFile bahaviour
diff --git a/helper/temporal/temporal.go b/helper/temporal/temporal.go
index e073b1d..c6470a1 100644
--- a/helper/temporal/temporal.go
+++ b/helper/temporal/temporal.go
@@ -1,6 +1,8 @@
package temporal
import (
+ "path/filepath"
+
"gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-billy.v3/util"
)
@@ -22,8 +24,8 @@
}
func (h *Temporal) TempFile(dir, prefix string) (billy.File, error) {
- if dir == "" {
- dir = h.defaultDir
+ if !filepath.IsAbs(dir) {
+ dir = h.Join(h.defaultDir, dir)
}
return util.TempFile(h.Filesystem, dir, prefix)
diff --git a/test/tempfile.go b/test/tempfile.go
index a50f2d4..a85f86b 100644
--- a/test/tempfile.go
+++ b/test/tempfile.go
@@ -25,11 +25,11 @@
}
func (s *TempFileSuite) TestTempFileWithPath(c *C) {
- f, err := s.FS.TempFile("foo", "bar")
+ f, err := s.FS.TempFile("qux", "bar")
c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)
- c.Assert(strings.HasPrefix(f.Name(), s.FS.Join("foo", "bar")), Equals, true)
+ c.Assert(strings.HasPrefix(f.Name(), s.FS.Join("foo", "qux", "bar")), Equals, true)
}
func (s *TempFileSuite) TestTempFileFullWithPath(c *C) {
@@ -37,7 +37,7 @@
c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)
- c.Assert(strings.Index(f.Name(), s.FS.Join("foo", "bar")), Not(Equals), -1)
+ c.Assert(strings.HasPrefix(f.Name(), s.FS.Join("foo", "bar")), Equals, true)
}
func (s *TempFileSuite) TestRemoveTempFile(c *C) {