pkg/ioutils: unify TempDir implementation

This allows us to maintain a single GoDoc string to describe
what it's used for.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-23 12:23:03 +01:00
parent 2e67c85c13
commit 3314f4ef09
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 7 additions and 12 deletions

View file

@ -1,11 +0,0 @@
//go:build !windows
// +build !windows
package ioutils // import "github.com/docker/docker/pkg/ioutils"
import "os"
// TempDir on Unix systems is equivalent to os.MkdirTemp.
func TempDir(dir, prefix string) (string, error) {
return os.MkdirTemp(dir, prefix)
}

View file

@ -2,15 +2,21 @@ package ioutils // import "github.com/docker/docker/pkg/ioutils"
import ( import (
"os" "os"
"runtime"
"github.com/docker/docker/pkg/longpath" "github.com/docker/docker/pkg/longpath"
) )
// TempDir is the equivalent of os.MkdirTemp, except that the result is in Windows longpath format. // TempDir is the equivalent of [os.MkdirTemp], except that on Windows
// the result is in Windows longpath format. On Unix systems it is
// equivalent to [os.MkdirTemp].
func TempDir(dir, prefix string) (string, error) { func TempDir(dir, prefix string) (string, error) {
tempDir, err := os.MkdirTemp(dir, prefix) tempDir, err := os.MkdirTemp(dir, prefix)
if err != nil { if err != nil {
return "", err return "", err
} }
if runtime.GOOS != "windows" {
return tempDir, nil
}
return longpath.AddPrefix(tempDir), nil return longpath.AddPrefix(tempDir), nil
} }