Skip to content

Commit 3d2c600

Browse files
authored
Merge pull request #9 from arduino/fix_tmp_canonical_paths
Ensure canonical path on MkTempDir (windows)
2 parents 5a57733 + bbb420d commit 3d2c600

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

constructors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NullPath() *Path {
4545

4646
// TempDir returns the default path to use for temporary files
4747
func TempDir() *Path {
48-
return New(os.TempDir())
48+
return New(os.TempDir()).Canonical()
4949
}
5050

5151
// MkTempDir creates a new temporary directory in the directory
@@ -57,7 +57,7 @@ func MkTempDir(dir, prefix string) (*Path, error) {
5757
if err != nil {
5858
return nil, err
5959
}
60-
return New(path), nil
60+
return New(path).Canonical(), nil
6161
}
6262

6363
// MkTempFile creates a new temporary file in the directory dir with a name beginning with prefix,

paths_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ func TestReadFileAsLines(t *testing.T) {
208208
require.Equal(t, "line 3", lines[3])
209209
}
210210

211+
func TestCanonicaTempDir(t *testing.T) {
212+
require.Equal(t, TempDir().String(), TempDir().Canonical().String())
213+
}
214+
211215
func TestCopyDir(t *testing.T) {
212216
tmp, err := MkTempDir("", "")
213217
require.NoError(t, err)
@@ -341,6 +345,10 @@ func TestCanonicalize(t *testing.T) {
341345

342346
r := New("c:\\").Canonical()
343347
require.Equal(t, "C:\\", r.String())
348+
349+
tmp, err := MkTempDir("", "pref")
350+
require.NoError(t, err)
351+
require.Equal(t, tmp.String(), tmp.Canonical().String())
344352
}
345353
}
346354

0 commit comments

Comments
 (0)