summaryrefslogtreecommitdiff
path: root/pkg/plugins
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2021-08-27 23:52:39 +0200
committerSebastiaan van Stijn <github@gone.nl>2021-08-31 15:42:54 +0200
commit303ea8e8206381fe34ef7716c7504e5d52b5df4e (patch)
treed9e98f07834f58835f0712fd3e616c059726ae8a /pkg/plugins
parent7bdf98276cd12bf7c4dbfe85ed2e29d272fedbd6 (diff)
downloaddocker-303ea8e8206381fe34ef7716c7504e5d52b5df4e.tar.gz
pkg/plugins: fix compatibility with go1.16
commit c55a4ac7795c7606b548b38e24673733481e2167 changed the ioutil utilities to use the new os variants, per recommendation from the go 1.16 release notes: https://golang.org/doc/go1.16#ioutil > we encourage new code to use the new definitions in the io and os packages. > Here is a list of the new locations of the names exported by io/ioutil: However, the devil is in the detail, and io.ReadDir() is not a direct replacement for ioutil.ReadDir(); > ReadDir => os.ReadDir (note: returns a slice of os.DirEntry rather than a slice of fs.FileInfo) go1.16 added a io.FileInfoToDirEntry() utility to concert a DirEntry to a FileInfo, but it's not available in go1.16 This patch copies the FileInfoToDirEntry code, and uses it for go1.16. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'pkg/plugins')
-rw-r--r--pkg/plugins/discovery.go3
-rw-r--r--pkg/plugins/utils.go8
-rw-r--r--pkg/plugins/utils_go1.16.go47
3 files changed, 56 insertions, 2 deletions
diff --git a/pkg/plugins/discovery.go b/pkg/plugins/discovery.go
index 9d972b3c21..f24673ed87 100644
--- a/pkg/plugins/discovery.go
+++ b/pkg/plugins/discovery.go
@@ -3,7 +3,6 @@ package plugins // import "github.com/docker/docker/pkg/plugins"
import (
"encoding/json"
"fmt"
- "io/fs"
"net/url"
"os"
"path/filepath"
@@ -41,7 +40,7 @@ func Scan() ([]string, error) {
continue
}
- entry = fs.FileInfoToDirEntry(fi)
+ entry = fileInfoToDirEntry(fi)
}
if entry.Type()&os.ModeSocket != 0 {
diff --git a/pkg/plugins/utils.go b/pkg/plugins/utils.go
new file mode 100644
index 0000000000..bd2344ff20
--- /dev/null
+++ b/pkg/plugins/utils.go
@@ -0,0 +1,8 @@
+//go:build go1.17
+// +build go1.17
+
+package plugins
+
+import "io/fs"
+
+var fileInfoToDirEntry = fs.FileInfoToDirEntry
diff --git a/pkg/plugins/utils_go1.16.go b/pkg/plugins/utils_go1.16.go
new file mode 100644
index 0000000000..ce8c21a039
--- /dev/null
+++ b/pkg/plugins/utils_go1.16.go
@@ -0,0 +1,47 @@
+//go:build !go1.17
+// +build !go1.17
+
+// This code is taken from https://github.com/golang/go/blob/go1.17/src/io/fs/readdir.go#L49-L77
+// and provides the io/fs.FileInfoToDirEntry() utility for go1.16. Go 1.16 and up
+// provide a new implementation of ioutil.ReadDir() (in os.ReadDir()) that returns
+// an os.DirEntry instead of fs.FileInfo. go1.17 added the io/fs.FileInfoToDirEntry()
+// utility to allow existing uses of ReadDir() to get the old type. This utility
+// is not available in go1.16, so we copied it to assist the migration to os.ReadDir().
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package plugins
+
+import "os"
+
+// dirInfo is a DirEntry based on a FileInfo.
+type dirInfo struct {
+ fileInfo os.FileInfo
+}
+
+func (di dirInfo) IsDir() bool {
+ return di.fileInfo.IsDir()
+}
+
+func (di dirInfo) Type() os.FileMode {
+ return di.fileInfo.Mode().Type()
+}
+
+func (di dirInfo) Info() (os.FileInfo, error) {
+ return di.fileInfo, nil
+}
+
+func (di dirInfo) Name() string {
+ return di.fileInfo.Name()
+}
+
+// fileInfoToDirEntry returns a DirEntry that returns information from info.
+// If info is nil, fileInfoToDirEntry returns nil.
+func fileInfoToDirEntry(info os.FileInfo) os.DirEntry {
+ if info == nil {
+ return nil
+ }
+ return dirInfo{fileInfo: info}
+}