Skip to content

Ensure canonical path on MkTempDir (windows) #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NullPath() *Path {

// TempDir returns the default path to use for temporary files
func TempDir() *Path {
return New(os.TempDir())
return New(os.TempDir()).Canonical()
}

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

// MkTempFile creates a new temporary file in the directory dir with a name beginning with prefix,
Expand Down
8 changes: 8 additions & 0 deletions paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func TestReadFileAsLines(t *testing.T) {
require.Equal(t, "line 3", lines[3])
}

func TestCanonicaTempDir(t *testing.T) {
require.Equal(t, TempDir().String(), TempDir().Canonical().String())
}

func TestCopyDir(t *testing.T) {
tmp, err := MkTempDir("", "")
require.NoError(t, err)
Expand Down Expand Up @@ -341,6 +345,10 @@ func TestCanonicalize(t *testing.T) {

r := New("c:\\").Canonical()
require.Equal(t, "C:\\", r.String())

tmp, err := MkTempDir("", "pref")
require.NoError(t, err)
require.Equal(t, tmp.String(), tmp.Canonical().String())
}
}

Expand Down