mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
bake: handle root evaluation with available drives for windows entitlement
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
9f429965c0
commit
f10be074b4
@ -319,7 +319,7 @@ func isParentOrEqualPath(p, parent string) bool {
|
||||
if p == parent || parent == "/" {
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(p, parent+string(filepath.Separator)) {
|
||||
if strings.HasPrefix(p, filepath.Clean(parent+string(filepath.Separator))) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@ -441,22 +441,6 @@ func removeCommonPaths(in, common []string) []string {
|
||||
return filtered
|
||||
}
|
||||
|
||||
func evaluatePaths(in []string) ([]string, error) {
|
||||
out := make([]string, 0, len(in))
|
||||
for _, p := range in {
|
||||
v, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err = filepath.EvalSymlinks(v)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func evaluateToExistingPaths(in map[string]struct{}) (map[string]struct{}, error) {
|
||||
m := make(map[string]struct{}, len(in))
|
||||
for p := range in {
|
||||
|
26
bake/entitlements_unix.go
Normal file
26
bake/entitlements_unix.go
Normal file
@ -0,0 +1,26 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package bake
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func evaluatePaths(in []string) ([]string, error) {
|
||||
out := make([]string, 0, len(in))
|
||||
for _, p := range in {
|
||||
v, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err = filepath.EvalSymlinks(v)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, nil
|
||||
}
|
39
bake/entitlements_windows.go
Normal file
39
bake/entitlements_windows.go
Normal file
@ -0,0 +1,39 @@
|
||||
package bake
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func evaluatePaths(in []string) ([]string, error) {
|
||||
out := make([]string, 0, len(in))
|
||||
for _, p := range in {
|
||||
if p == "/" {
|
||||
out = append(out, getAllVolumes()...)
|
||||
continue
|
||||
}
|
||||
v, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err = filepath.EvalSymlinks(v)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to evaluate path %q", p)
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func getAllVolumes() []string {
|
||||
var volumes []string
|
||||
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
|
||||
p := string(drive) + ":" + string(filepath.Separator)
|
||||
if _, err := os.Stat(p); !os.IsNotExist(err) {
|
||||
volumes = append(volumes, p)
|
||||
}
|
||||
}
|
||||
return volumes
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user