mirror of https://github.com/docker/cli.git
Compare commits
14 Commits
68867d8fdb
...
7bb085b02a
Author | SHA1 | Date |
---|---|---|
Will Wang | 7bb085b02a | |
Sebastiaan van Stijn | a5fb752ecf | |
Laura Brehm | 4e64c59d64 | |
Jonathan A. Sternberg | 3472bbc28a | |
Laura Brehm | 649e564ee0 | |
Sebastiaan van Stijn | e1213edcc6 | |
Jonathan A. Sternberg | b1956f5073 | |
Will Wang | 01182919b3 | |
Will Wang | a85a37e3f3 | |
Will Wang | 40df26561b | |
Will Wang | efaf3c92e6 | |
Will Wang | c6d1de3397 | |
Will Wang | 115fdd979b | |
Will Wang | c90705a413 |
|
@ -67,7 +67,7 @@ jobs:
|
|||
name: Update Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
go-version: 1.22.7
|
||||
-
|
||||
name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
|
|
|
@ -180,7 +180,7 @@ func toWslPath(s string) string {
|
|||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("mnt/%s%s", drive, p)
|
||||
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
|
||||
}
|
||||
|
||||
func parseUNCPath(s string) (drive, p string, ok bool) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/url"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
@ -9,21 +10,48 @@ import (
|
|||
)
|
||||
|
||||
func TestWslSocketPath(t *testing.T) {
|
||||
u, err := url.Parse("unix:////./c:/my/file/path")
|
||||
assert.NilError(t, err)
|
||||
testCases := []struct {
|
||||
doc string
|
||||
fs fs.FS
|
||||
url string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
doc: "filesystem where WSL path does not exist",
|
||||
fs: fstest.MapFS{
|
||||
"my/file/path": {},
|
||||
},
|
||||
url: "unix:////./c:/my/file/path",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
doc: "filesystem where WSL path exists",
|
||||
fs: fstest.MapFS{
|
||||
"mnt/c/my/file/path": {},
|
||||
},
|
||||
url: "unix:////./c:/my/file/path",
|
||||
expected: "/mnt/c/my/file/path",
|
||||
},
|
||||
{
|
||||
doc: "filesystem where WSL path exists uppercase URL",
|
||||
fs: fstest.MapFS{
|
||||
"mnt/c/my/file/path": {},
|
||||
},
|
||||
url: "unix:////./C:/my/file/path",
|
||||
expected: "/mnt/c/my/file/path",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.doc, func(t *testing.T) {
|
||||
u, err := url.Parse(tc.url)
|
||||
assert.NilError(t, err)
|
||||
// Ensure host is empty.
|
||||
assert.Equal(t, u.Host, "")
|
||||
|
||||
// Use a filesystem where the WSL path exists.
|
||||
fs := fstest.MapFS{
|
||||
"mnt/c/my/file/path": {},
|
||||
}
|
||||
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
|
||||
result := wslSocketPath(u.Path, tc.fs)
|
||||
|
||||
// Use a filesystem where the WSL path doesn't exist.
|
||||
fs = fstest.MapFS{
|
||||
"my/file/path": {},
|
||||
assert.Equal(t, result, tc.expected)
|
||||
})
|
||||
}
|
||||
assert.Equal(t, wslSocketPath(u.Path, fs), "")
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/docker/cli/cli/version"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
|
|||
metric.WithAttributes(cmdStatusAttrs...),
|
||||
)
|
||||
if mp, ok := mp.(MeterProvider); ok {
|
||||
mp.ForceFlush(ctx)
|
||||
if err := mp.ForceFlush(ctx); err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,10 +167,13 @@ func (configFile *ConfigFile) Save() (retErr error) {
|
|||
return errors.Wrap(err, "error closing temp file")
|
||||
}
|
||||
|
||||
// Handle situation where the configfile is a symlink
|
||||
// Handle situation where the configfile is a symlink, and allow for dangling symlinks
|
||||
cfgFile := configFile.Filename
|
||||
if f, err := os.Readlink(cfgFile); err == nil {
|
||||
if f, err := filepath.EvalSymlinks(cfgFile); err == nil {
|
||||
cfgFile = f
|
||||
} else if os.IsNotExist(err) {
|
||||
// extract the path from the error if the configfile does not exist or is a dangling symlink
|
||||
cfgFile = err.(*os.PathError).Path
|
||||
}
|
||||
|
||||
// Try copying the current config file (if any) ownership and permissions
|
||||
|
|
|
@ -538,6 +538,34 @@ func TestSaveWithSymlink(t *testing.T) {
|
|||
assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
|
||||
}
|
||||
|
||||
func TestSaveWithRelativeSymlink(t *testing.T) {
|
||||
dir := fs.NewDir(t, t.Name(), fs.WithFile("real-config.json", `{}`))
|
||||
defer dir.Remove()
|
||||
|
||||
symLink := dir.Join("config.json")
|
||||
relativeRealFile := "real-config.json"
|
||||
realFile := dir.Join(relativeRealFile)
|
||||
err := os.Symlink(relativeRealFile, symLink)
|
||||
assert.NilError(t, err)
|
||||
|
||||
configFile := New(symLink)
|
||||
|
||||
err = configFile.Save()
|
||||
assert.NilError(t, err)
|
||||
|
||||
fi, err := os.Lstat(symLink)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, fi.Mode()&os.ModeSymlink != 0, "expected %s to be a symlink", symLink)
|
||||
|
||||
cfg, err := os.ReadFile(symLink)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
|
||||
|
||||
cfg, err = os.ReadFile(realFile)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
|
||||
}
|
||||
|
||||
func TestPluginConfig(t *testing.T) {
|
||||
configFile := New("test-plugin")
|
||||
defer os.Remove("test-plugin")
|
||||
|
|
|
@ -358,7 +358,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
|
|||
|
||||
mp := dockerCli.MeterProvider()
|
||||
if mp, ok := mp.(command.MeterProvider); ok {
|
||||
defer mp.Shutdown(ctx)
|
||||
if err := mp.Shutdown(ctx); err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
} else {
|
||||
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue