Skip to content

Commit c63ea32

Browse files
committed
pkg/ioutils: TempDir: move to pkg/longpath
This utility wasn't very related to all other utilities in pkg/ioutils. Moving it to longpath to also make it more clear what it does. It looks like there's only a single (public) external consumer of this utility, and only used in a test, and it's not 100% clear if it was intentional to use our package, of if it was a case of "I actually meant `io/ioutil.MkdirTemp`" so we could consider skipping the alias. While moving the package, I also renamed `TempDir` to `MkdirTemp`, which is the signature it matches in "os" from stdlib. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 3314f4e commit c63ea32

7 files changed

Lines changed: 34 additions & 34 deletions

File tree

builder/builder-next/adapters/snapshot/layer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"path/filepath"
77

88
"github.com/docker/docker/layer"
9-
"github.com/docker/docker/pkg/ioutils"
9+
"github.com/docker/docker/pkg/longpath"
1010
"github.com/pkg/errors"
1111
bolt "go.etcd.io/bbolt"
1212
"golang.org/x/sync/errgroup"
@@ -55,7 +55,7 @@ func (s *snapshotter) EnsureLayer(ctx context.Context, key string) ([]layer.Diff
5555
})
5656
}
5757

58-
tmpDir, err := ioutils.TempDir("", "docker-tarsplit")
58+
tmpDir, err := longpath.MkdirTemp("", "docker-tarsplit")
5959
if err != nil {
6060
return nil, err
6161
}

builder/dockerfile/copy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/docker/docker/pkg/archive"
2020
"github.com/docker/docker/pkg/containerfs"
2121
"github.com/docker/docker/pkg/idtools"
22-
"github.com/docker/docker/pkg/ioutils"
22+
"github.com/docker/docker/pkg/longpath"
2323
"github.com/docker/docker/pkg/progress"
2424
"github.com/docker/docker/pkg/streamformatter"
2525
"github.com/docker/docker/pkg/system"
@@ -390,7 +390,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b
390390
filename := getFilenameForDownload(u.Path, resp)
391391

392392
// Prepare file in a tmp dir
393-
tmpDir, err := ioutils.TempDir("", "docker-remote")
393+
tmpDir, err := longpath.MkdirTemp("", "docker-remote")
394394
if err != nil {
395395
return
396396
}

builder/remotecontext/archive.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/docker/docker/pkg/archive"
1010
"github.com/docker/docker/pkg/chrootarchive"
1111
"github.com/docker/docker/pkg/containerfs"
12-
"github.com/docker/docker/pkg/ioutils"
12+
"github.com/docker/docker/pkg/longpath"
1313
"github.com/docker/docker/pkg/tarsum"
1414
"github.com/pkg/errors"
1515
)
@@ -47,7 +47,7 @@ type modifiableContext interface {
4747
//
4848
// Closing tarStream has to be done by the caller.
4949
func FromArchive(tarStream io.Reader) (builder.Source, error) {
50-
root, err := ioutils.TempDir("", "docker-builder")
50+
root, err := longpath.MkdirTemp("", "docker-builder")
5151
if err != nil {
5252
return nil, err
5353
}

container/view.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,12 @@ func (db *ViewDB) GetByPrefix(s string) (string, error) {
138138
if s == "" {
139139
return "", ErrEmptyPrefix
140140
}
141-
txn := db.store.Txn(false)
142-
iter, err := txn.Get(memdbContainersTable, memdbIDIndexPrefix, s)
141+
iter, err := db.store.Txn(false).Get(memdbContainersTable, memdbIDIndexPrefix, s)
143142
if err != nil {
144143
return "", err
145144
}
146145

147-
var (
148-
id string
149-
)
150-
146+
var id string
151147
for {
152148
item := iter.Next()
153149
if item == nil {

pkg/ioutils/tempdir.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkg/ioutils/tempdir_deprecated.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ioutils
2+
3+
import "github.com/docker/docker/pkg/longpath"
4+
5+
// TempDir is the equivalent of [os.MkdirTemp], except that on Windows
6+
// the result is in Windows longpath format. On Unix systems it is
7+
// equivalent to [os.MkdirTemp].
8+
//
9+
// Deprecated: use [longpath.MkdirTemp].
10+
var TempDir = longpath.MkdirTemp

pkg/longpath/longpath.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package longpath // import "github.com/docker/docker/pkg/longpath"
77

88
import (
9+
"os"
10+
"runtime"
911
"strings"
1012
)
1113

@@ -25,3 +27,17 @@ func AddPrefix(path string) string {
2527
}
2628
return path
2729
}
30+
31+
// MkdirTemp is the equivalent of [os.MkdirTemp], except that on Windows
32+
// the result is in Windows longpath format. On Unix systems it is
33+
// equivalent to [os.MkdirTemp].
34+
func MkdirTemp(dir, prefix string) (string, error) {
35+
tempDir, err := os.MkdirTemp(dir, prefix)
36+
if err != nil {
37+
return "", err
38+
}
39+
if runtime.GOOS != "windows" {
40+
return tempDir, nil
41+
}
42+
return AddPrefix(tempDir), nil
43+
}

0 commit comments

Comments
 (0)