mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 17:37:46 +08:00
bake: windows entitlement path fixes take 2
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f3929447d7
commit
9f429965c0
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/docker/buildx/build"
|
"github.com/docker/buildx/build"
|
||||||
|
"github.com/docker/buildx/util/osutil"
|
||||||
"github.com/moby/buildkit/util/entitlements"
|
"github.com/moby/buildkit/util/entitlements"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -463,6 +464,10 @@ func evaluateToExistingPaths(in map[string]struct{}) (map[string]struct{}, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
||||||
}
|
}
|
||||||
|
v, err = osutil.GetLongPathName(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
||||||
|
}
|
||||||
m[v] = struct{}{}
|
m[v] = struct{}{}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
@ -4,12 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"slices"
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/buildx/build"
|
"github.com/docker/buildx/build"
|
||||||
"github.com/docker/buildx/controller/pb"
|
"github.com/docker/buildx/controller/pb"
|
||||||
|
"github.com/docker/buildx/util/osutil"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
"github.com/moby/buildkit/client/llb"
|
"github.com/moby/buildkit/client/llb"
|
||||||
"github.com/moby/buildkit/util/entitlements"
|
"github.com/moby/buildkit/util/entitlements"
|
||||||
@ -17,24 +17,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestEvaluateToExistingPath(t *testing.T) {
|
func TestEvaluateToExistingPath(t *testing.T) {
|
||||||
tempDir := t.TempDir()
|
tempDir, err := osutil.GetLongPathName(t.TempDir())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Setup temporary directory structure for testing
|
// Setup temporary directory structure for testing
|
||||||
existingFile := filepath.Join(tempDir, "existing_file")
|
existingFile := filepath.Join(tempDir, "existing_file")
|
||||||
err := os.WriteFile(existingFile, []byte("test"), 0644)
|
require.NoError(t, os.WriteFile(existingFile, []byte("test"), 0644))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
existingDir := filepath.Join(tempDir, "existing_dir")
|
existingDir := filepath.Join(tempDir, "existing_dir")
|
||||||
err = os.Mkdir(existingDir, 0755)
|
require.NoError(t, os.Mkdir(existingDir, 0755))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
symlinkToFile := filepath.Join(tempDir, "symlink_to_file")
|
symlinkToFile := filepath.Join(tempDir, "symlink_to_file")
|
||||||
err = os.Symlink(existingFile, symlinkToFile)
|
require.NoError(t, os.Symlink(existingFile, symlinkToFile))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
symlinkToDir := filepath.Join(tempDir, "symlink_to_dir")
|
symlinkToDir := filepath.Join(tempDir, "symlink_to_dir")
|
||||||
err = os.Symlink(existingDir, symlinkToDir)
|
require.NoError(t, os.Symlink(existingDir, symlinkToDir))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
nonexistentPath := filepath.Join(tempDir, "nonexistent", "path", "file.txt")
|
nonexistentPath := filepath.Join(tempDir, "nonexistent", "path", "file.txt")
|
||||||
|
|
||||||
@ -84,10 +81,7 @@ func TestEvaluateToExistingPath(t *testing.T) {
|
|||||||
name: "Root path",
|
name: "Root path",
|
||||||
input: "/",
|
input: "/",
|
||||||
expected: func() string {
|
expected: func() string {
|
||||||
root := "/"
|
root, _ := filepath.Abs("/")
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
root = filepath.VolumeName(root)
|
|
||||||
}
|
|
||||||
return root
|
return root
|
||||||
}(),
|
}(),
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
@ -109,8 +103,7 @@ func TestEvaluateToExistingPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDedupePaths(t *testing.T) {
|
func TestDedupePaths(t *testing.T) {
|
||||||
wd, err := os.Getwd()
|
wd := osutil.GetWd()
|
||||||
require.NoError(t, err)
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
in map[string]struct{}
|
in map[string]struct{}
|
||||||
out map[string]struct{}
|
out map[string]struct{}
|
||||||
@ -172,21 +165,25 @@ func TestDedupePaths(t *testing.T) {
|
|||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
m[filepath.ToSlash(v)] = struct{}{}
|
m[filepath.ToSlash(v)] = struct{}{}
|
||||||
}
|
}
|
||||||
require.Equal(t, tc.out, m)
|
o := make(map[string]struct{}, len(tc.out))
|
||||||
|
for k := range tc.out {
|
||||||
|
o[filepath.ToSlash(k)] = struct{}{}
|
||||||
|
}
|
||||||
|
require.Equal(t, o, m)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateEntitlements(t *testing.T) {
|
func TestValidateEntitlements(t *testing.T) {
|
||||||
dir1 := t.TempDir()
|
dir1, err := osutil.GetLongPathName(t.TempDir())
|
||||||
dir2 := t.TempDir()
|
require.NoError(t, err)
|
||||||
|
dir2, err := osutil.GetLongPathName(t.TempDir())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
escapeLink := filepath.Join(dir1, "escape_link")
|
escapeLink := filepath.Join(dir1, "escape_link")
|
||||||
err := os.Symlink("../../aa", escapeLink)
|
require.NoError(t, os.Symlink("../../aa", escapeLink))
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd := osutil.GetWd()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user