Merge pull request #44515 from thaJeztah/move_ioutils_tempdir
pkg/ioutils: TempDir: move to pkg/longpath
This commit is contained in:
commit
298d3aa8b8
9 changed files with 42 additions and 47 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
}
|
10
pkg/ioutils/tempdir_deprecated.go
Normal file
10
pkg/ioutils/tempdir_deprecated.go
Normal file
|
@ -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
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue