From 3314f4ef09fbe6fa4c32f1b114959388d75210a4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 23 Nov 2022 12:23:03 +0100 Subject: [PATCH] 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 --- pkg/ioutils/temp_unix.go | 11 ----------- pkg/ioutils/{temp_windows.go => tempdir.go} | 8 +++++++- 2 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 pkg/ioutils/temp_unix.go rename pkg/ioutils/{temp_windows.go => tempdir.go} (55%) diff --git a/pkg/ioutils/temp_unix.go b/pkg/ioutils/temp_unix.go deleted file mode 100644 index 7489122309..0000000000 --- a/pkg/ioutils/temp_unix.go +++ /dev/null @@ -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) -} diff --git a/pkg/ioutils/temp_windows.go b/pkg/ioutils/tempdir.go similarity index 55% rename from pkg/ioutils/temp_windows.go rename to pkg/ioutils/tempdir.go index a57fd9af6a..3555458e9f 100644 --- a/pkg/ioutils/temp_windows.go +++ b/pkg/ioutils/tempdir.go @@ -2,15 +2,21 @@ package ioutils // import "github.com/docker/docker/pkg/ioutils" import ( "os" + "runtime" "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) { tempDir, err := os.MkdirTemp(dir, prefix) if err != nil { return "", err } + if runtime.GOOS != "windows" { + return tempDir, nil + } return longpath.AddPrefix(tempDir), nil }