Compare commits

...

14 Commits

Author SHA1 Message Date
Will Wang 7bb085b02a
Merge 01182919b3 into a5fb752ecf 2024-09-18 15:34:59 +01:00
Sebastiaan van Stijn a5fb752ecf
Merge pull request #5445 from jsternberg/lowercase-windows-drive
command: change drive to lowercase for wsl path
2024-09-18 12:15:45 +02:00
Laura Brehm 4e64c59d64
Merge pull request #5446 from thaJeztah/codeql_updates
gha: update codeql workflow to go1.22.7
2024-09-18 11:04:32 +01:00
Jonathan A. Sternberg 3472bbc28a
command: change drive to lowercase for wsl path
On Windows, the drive casing doesn't matter outside of WSL. For WSL, the
drives are lowercase. When we're producing a WSL path, lowercase the
drive letter.

Co-authored-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Co-authored-by: Laura Brehm <laurabrehm@hey.com>

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-09-18 10:59:08 +01:00
Laura Brehm 649e564ee0
Merge pull request #5444 from jsternberg/handle-otel-errors
telemetry: pass otel errors to the otel handler for shutdown and force flush
2024-09-18 10:39:55 +01:00
Sebastiaan van Stijn e1213edcc6
gha: update codeql workflow to go1.22.7
commit d7d56599ca updated this
repository to go1.22, but the codeql action didn't specify a
patch version, and was missed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 21:39:56 +02:00
Jonathan A. Sternberg b1956f5073
telemetry: pass otel errors to the otel handler for shutdown and force flush
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-17 10:47:04 -05:00
Will Wang 01182919b3
update comments
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-24 15:15:59 +08:00
Will Wang a85a37e3f3
better to limit the scope of err
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-24 14:36:34 +08:00
Will Wang 40df26561b
use os.PathError to avoid an extra import
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-24 13:26:44 +08:00
Will Wang efaf3c92e6
extract path from error when NotExist error occurs
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-24 13:22:06 +08:00
Will Wang c6d1de3397
allow for dangling symlinks
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-24 12:10:32 +08:00
Will Wang 115fdd979b
Update cli/config/configfile/file.go
use filepath.EvalSymlink instead of check with filepath.IsAbs

Co-authored-by: Paweł Gronowski <me@woland.xyz>
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-23 23:17:09 +08:00
Will Wang c90705a413
fix bug with config file being a relative symlink
Signed-off-by: Will Wang <willww64@gmail.com>
2024-07-23 22:16:41 +08:00
7 changed files with 84 additions and 20 deletions

View File

@ -67,7 +67,7 @@ jobs:
name: Update Go name: Update Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.21' go-version: 1.22.7
- -
name: Initialize CodeQL name: Initialize CodeQL
uses: github/codeql-action/init@v3 uses: github/codeql-action/init@v3

View File

@ -180,7 +180,7 @@ func toWslPath(s string) string {
if !ok { if !ok {
return "" 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) { func parseUNCPath(s string) (drive, p string, ok bool) {

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"io/fs"
"net/url" "net/url"
"testing" "testing"
"testing/fstest" "testing/fstest"
@ -9,21 +10,48 @@ import (
) )
func TestWslSocketPath(t *testing.T) { func TestWslSocketPath(t *testing.T) {
u, err := url.Parse("unix:////./c:/my/file/path") testCases := []struct {
assert.NilError(t, err) 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. // Ensure host is empty.
assert.Equal(t, u.Host, "") assert.Equal(t, u.Host, "")
// Use a filesystem where the WSL path exists. result := wslSocketPath(u.Path, tc.fs)
fs := fstest.MapFS{
"mnt/c/my/file/path": {},
}
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
// Use a filesystem where the WSL path doesn't exist. assert.Equal(t, result, tc.expected)
fs = fstest.MapFS{ })
"my/file/path": {},
} }
assert.Equal(t, wslSocketPath(u.Path, fs), "")
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/docker/cli/cli/version" "github.com/docker/cli/cli/version"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric"
) )
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
metric.WithAttributes(cmdStatusAttrs...), metric.WithAttributes(cmdStatusAttrs...),
) )
if mp, ok := mp.(MeterProvider); ok { if mp, ok := mp.(MeterProvider); ok {
mp.ForceFlush(ctx) if err := mp.ForceFlush(ctx); err != nil {
otel.Handle(err)
}
} }
} }
} }

View File

@ -167,10 +167,13 @@ func (configFile *ConfigFile) Save() (retErr error) {
return errors.Wrap(err, "error closing temp file") 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 cfgFile := configFile.Filename
if f, err := os.Readlink(cfgFile); err == nil { if f, err := filepath.EvalSymlinks(cfgFile); err == nil {
cfgFile = f 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 // Try copying the current config file (if any) ownership and permissions

View File

@ -538,6 +538,34 @@ func TestSaveWithSymlink(t *testing.T) {
assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}")) 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) { func TestPluginConfig(t *testing.T) {
configFile := New("test-plugin") configFile := New("test-plugin")
defer os.Remove("test-plugin") defer os.Remove("test-plugin")

View File

@ -358,7 +358,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
mp := dockerCli.MeterProvider() mp := dockerCli.MeterProvider()
if mp, ok := mp.(command.MeterProvider); ok { if mp, ok := mp.(command.MeterProvider); ok {
defer mp.Shutdown(ctx) if err := mp.Shutdown(ctx); err != nil {
otel.Handle(err)
}
} else { } else {
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed") fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
} }