diff --git a/builder/builder-next/adapters/snapshot/layer.go b/builder/builder-next/adapters/snapshot/layer.go index ed13def16fdee09a031e0337f46c2d2248208ef6..e606a8b472333239a141b74160ed1b8d1aa9df31 100644 --- a/builder/builder-next/adapters/snapshot/layer.go +++ b/builder/builder-next/adapters/snapshot/layer.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/docker/docker/layer" - "github.com/docker/docker/pkg/ioutils" + "github.com/docker/docker/pkg/longpath" "github.com/pkg/errors" bolt "go.etcd.io/bbolt" "golang.org/x/sync/errgroup" @@ -55,7 +55,7 @@ func (s *snapshotter) EnsureLayer(ctx context.Context, key string) ([]layer.Diff }) } - tmpDir, err := ioutils.TempDir("", "docker-tarsplit") + tmpDir, err := longpath.MkdirTemp("", "docker-tarsplit") if err != nil { return nil, err } diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index a69deb0f36b10ca8df00553aa8144c25d07e1ea2..0a994067fcb2267b8a3d3b9a0f901a2c37e352d1 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -19,7 +19,7 @@ import ( "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" - "github.com/docker/docker/pkg/ioutils" + "github.com/docker/docker/pkg/longpath" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/system" @@ -390,7 +390,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b filename := getFilenameForDownload(u.Path, resp) // Prepare file in a tmp dir - tmpDir, err := ioutils.TempDir("", "docker-remote") + tmpDir, err := longpath.MkdirTemp("", "docker-remote") if err != nil { return } diff --git a/builder/remotecontext/archive.go b/builder/remotecontext/archive.go index 9d89329040fcba51021397f4f4d7fe752eca1b17..bfe937b9aa508c936181dff1d36334e19b375546 100644 --- a/builder/remotecontext/archive.go +++ b/builder/remotecontext/archive.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/chrootarchive" "github.com/docker/docker/pkg/containerfs" - "github.com/docker/docker/pkg/ioutils" + "github.com/docker/docker/pkg/longpath" "github.com/docker/docker/pkg/tarsum" "github.com/pkg/errors" ) @@ -47,7 +47,7 @@ type modifiableContext interface { // // Closing tarStream has to be done by the caller. func FromArchive(tarStream io.Reader) (builder.Source, error) { - root, err := ioutils.TempDir("", "docker-builder") + root, err := longpath.MkdirTemp("", "docker-builder") if err != nil { return nil, err } diff --git a/container/view.go b/container/view.go index 3c4864494611084b816d430912dce6dfa2c92270..aa325366949800d86ea2e07bc1f0fe728166e575 100644 --- a/container/view.go +++ b/container/view.go @@ -138,16 +138,12 @@ func (db *ViewDB) GetByPrefix(s string) (string, error) { if s == "" { return "", ErrEmptyPrefix } - txn := db.store.Txn(false) - iter, err := txn.Get(memdbContainersTable, memdbIDIndexPrefix, s) + iter, err := db.store.Txn(false).Get(memdbContainersTable, memdbIDIndexPrefix, s) if err != nil { return "", err } - var ( - id string - ) - + var id string for { item := iter.Next() if item == nil { diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 0b6ad7f76861d56d17890c047d3703fdca7ce8e0..672f43c0cac99a7a3fd3e295212168b0b3d9df6e 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -26,7 +26,6 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build" - "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/stringid" "github.com/docker/docker/testutil/request" "github.com/docker/docker/volume" @@ -1738,7 +1737,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsValidation(c *testing.T) { } if testEnv.IsLocalDaemon() { - tmpDir, err := ioutils.TempDir("", "test-mounts-api") + tmpDir, err := os.MkdirTemp("", "test-mounts-api") assert.NilError(c, err) defer os.RemoveAll(tmpDir) cases = append(cases, []testCase{ @@ -2051,7 +2050,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) { // for modes only supported on Linux if DaemonIsLinux() { - tmpDir3, err := ioutils.TempDir("", "test-mounts-api-3") + tmpDir3, err := os.MkdirTemp("", "test-mounts-api-3") assert.NilError(c, err) defer os.RemoveAll(tmpDir3) diff --git a/pkg/ioutils/temp_unix.go b/pkg/ioutils/temp_unix.go deleted file mode 100644 index 748912230982406bab70b6912bcd7a336df5e3b0..0000000000000000000000000000000000000000 --- 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/temp_windows.go deleted file mode 100644 index a57fd9af6a87405d3bcfd84f3ac4c1a697355538..0000000000000000000000000000000000000000 --- a/pkg/ioutils/temp_windows.go +++ /dev/null @@ -1,16 +0,0 @@ -package ioutils // import "github.com/docker/docker/pkg/ioutils" - -import ( - "os" - - "github.com/docker/docker/pkg/longpath" -) - -// TempDir is the equivalent of os.MkdirTemp, except that the result is in Windows longpath format. -func TempDir(dir, prefix string) (string, error) { - tempDir, err := os.MkdirTemp(dir, prefix) - if err != nil { - return "", err - } - return longpath.AddPrefix(tempDir), nil -} diff --git a/pkg/ioutils/tempdir_deprecated.go b/pkg/ioutils/tempdir_deprecated.go new file mode 100644 index 0000000000000000000000000000000000000000..b3321602c2e4ca05b1ceb33682fce190e8710ff2 --- /dev/null +++ b/pkg/ioutils/tempdir_deprecated.go @@ -0,0 +1,10 @@ +package ioutils + +import "github.com/docker/docker/pkg/longpath" + +// 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]. +// +// Deprecated: use [longpath.MkdirTemp]. +var TempDir = longpath.MkdirTemp diff --git a/pkg/longpath/longpath.go b/pkg/longpath/longpath.go index 4177affba24210da8a88ab34b9dba88b0842638b..1c5dde5218f1d329b39473ad0ff026bb9693ed07 100644 --- a/pkg/longpath/longpath.go +++ b/pkg/longpath/longpath.go @@ -1,17 +1,20 @@ -// longpath introduces some constants and helper functions for handling long paths -// in Windows, which are expected to be prepended with `\\?\` and followed by either -// a drive letter, a UNC server\share, or a volume identifier. - +// Package longpath introduces some constants and helper functions for handling +// long paths in Windows. +// +// Long paths are expected to be prepended with "\\?\" and followed by either a +// drive letter, a UNC server\share, or a volume identifier. package longpath // import "github.com/docker/docker/pkg/longpath" import ( + "os" + "runtime" "strings" ) // Prefix is the longpath prefix for Windows file paths. const Prefix = `\\?\` -// AddPrefix will add the Windows long path prefix to the path provided if +// AddPrefix adds the Windows long path prefix to the path provided if // it does not already have it. func AddPrefix(path string) string { if !strings.HasPrefix(path, Prefix) { @@ -24,3 +27,17 @@ func AddPrefix(path string) string { } return path } + +// MkdirTemp 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 MkdirTemp(dir, prefix string) (string, error) { + tempDir, err := os.MkdirTemp(dir, prefix) + if err != nil { + return "", err + } + if runtime.GOOS != "windows" { + return tempDir, nil + } + return AddPrefix(tempDir), nil +}