fix windows glob issue (#1572)
This commit is contained in:
parent
0a4894f7ed
commit
59ee3ce862
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -3230,7 +3231,7 @@ func (st *HelmState) setFlags(setValues []SetValue) ([]string, error) {
|
||||||
}
|
}
|
||||||
flags = append(flags, "--set", fmt.Sprintf("%s=%s", escape(set.Name), escape(renderedValue[0])))
|
flags = append(flags, "--set", fmt.Sprintf("%s=%s", escape(set.Name), escape(renderedValue[0])))
|
||||||
} else if set.File != "" {
|
} else if set.File != "" {
|
||||||
flags = append(flags, "--set-file", fmt.Sprintf("%s=%s", escape(set.Name), st.storage().normalizePath(set.File)))
|
flags = append(flags, "--set-file", fmt.Sprintf("%s=%s", escape(set.Name), st.storage().normalizeSetFilePath(set.File, runtime.GOOS)))
|
||||||
} else if len(set.Values) > 0 {
|
} else if len(set.Values) > 0 {
|
||||||
renderedValues, err := renderValsSecrets(st.valsRuntime, set.Values...)
|
renderedValues, err := renderValsSecrets(st.valsRuntime, set.Values...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -136,7 +135,7 @@ func (st *Storage) normalizePath(path string) string {
|
||||||
if u != nil && (u.Scheme != "" || filepath.IsAbs(path)) {
|
if u != nil && (u.Scheme != "" || filepath.IsAbs(path)) {
|
||||||
return path
|
return path
|
||||||
} else {
|
} else {
|
||||||
return st.JoinBase(path, runtime.GOOS)
|
return st.JoinBase(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,10 +143,15 @@ func (st *Storage) normalizePath(path string) string {
|
||||||
// Helm's setFiles command does not support unescaped filepath separators (\) on Windows.
|
// Helm's setFiles command does not support unescaped filepath separators (\) on Windows.
|
||||||
// Instead, it requires double backslashes (\\) as filepath separators.
|
// Instead, it requires double backslashes (\\) as filepath separators.
|
||||||
// See https://github.com/helm/helm/issues/9537
|
// See https://github.com/helm/helm/issues/9537
|
||||||
func (st *Storage) JoinBase(relPath, GOOS string) string {
|
func (st *Storage) JoinBase(relPath string) string {
|
||||||
path := filepath.Join(st.basePath, relPath)
|
path := filepath.Join(st.basePath, relPath)
|
||||||
if GOOS == "windows" {
|
|
||||||
return strings.ReplaceAll(path, "\\", "\\\\")
|
|
||||||
}
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *Storage) normalizeSetFilePath(path, goos string) string {
|
||||||
|
normalizedPath := st.normalizePath(path)
|
||||||
|
if goos == "windows" {
|
||||||
|
return strings.ReplaceAll(normalizedPath, "\\", "\\\\")
|
||||||
|
}
|
||||||
|
return normalizedPath
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package state
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -176,39 +177,101 @@ func TestJoinBase(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
base string
|
base string
|
||||||
goos string
|
|
||||||
path string
|
path string
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "joinBase with non-root base",
|
name: "joinBase with non-root base",
|
||||||
base: "/root",
|
base: "/root",
|
||||||
goos: "linux",
|
|
||||||
path: "local/timespan-application.yml",
|
path: "local/timespan-application.yml",
|
||||||
want: "/local/timespan-application.yml",
|
want: "/local/timespan-application.yml",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "joinBase with root path",
|
name: "joinBase with root path",
|
||||||
base: "/",
|
base: "/",
|
||||||
goos: "linux",
|
|
||||||
path: "data/timespan-application.yml",
|
path: "data/timespan-application.yml",
|
||||||
want: "/data/timespan-application.yml",
|
want: "/data/timespan-application.yml",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "windows joinBase",
|
name: "windows joinBase",
|
||||||
base: "",
|
base: "",
|
||||||
goos: "windows",
|
|
||||||
path: "data\\timespan-application.yml",
|
path: "data\\timespan-application.yml",
|
||||||
want: "data\\\\timespan-application.yml",
|
want: "data\\timespan-application.yml",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
storageIns := NewStorage(tt.base, helmexec.NewLogger(io.Discard, "debug"), filesystem.DefaultFileSystem())
|
storageIns := NewStorage(tt.base, helmexec.NewLogger(io.Discard, "debug"), filesystem.DefaultFileSystem())
|
||||||
if got := storageIns.JoinBase(tt.path, tt.goos); got != tt.want {
|
if got := storageIns.JoinBase(tt.path); got != tt.want {
|
||||||
t.Errorf("JoinBase() = %v, want %v", got, tt.want)
|
t.Errorf("JoinBase() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizeSetFilePath(t *testing.T) {
|
||||||
|
st := &Storage{
|
||||||
|
basePath: "/base/path",
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
expected string
|
||||||
|
osGOOS string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Unix path on Unix",
|
||||||
|
path: "relative/path",
|
||||||
|
expected: "/base/path/relative/path",
|
||||||
|
osGOOS: "linux",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Windows path on Windows",
|
||||||
|
path: "relative\\path",
|
||||||
|
expected: "/base/path/relative\\\\path",
|
||||||
|
osGOOS: "windows",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Unix path on Windows",
|
||||||
|
path: "relative/path",
|
||||||
|
expected: "/base/path/relative/path",
|
||||||
|
osGOOS: "windows",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Absolute path on Unix",
|
||||||
|
path: "/absolute/path",
|
||||||
|
expected: "/absolute/path",
|
||||||
|
osGOOS: "linux",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Absolute path on Windows",
|
||||||
|
path: "C:\\absolute\\path",
|
||||||
|
expected: "C:\\\\absolute\\\\path",
|
||||||
|
osGOOS: "windows",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
result := st.normalizeSetFilePath(tt.path, tt.osGOOS)
|
||||||
|
if tt.osGOOS == "windows" {
|
||||||
|
if result != tt.expected {
|
||||||
|
t.Errorf("normalizeSetFilePath() = %v, want %v", result, tt.expected)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
expectedPath := filepath.Join(st.basePath, tt.path)
|
||||||
|
if !filepath.IsAbs(tt.path) {
|
||||||
|
if result != expectedPath {
|
||||||
|
t.Errorf("normalizeSetFilePath() = %v, want %v", result, expectedPath)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if result != tt.path {
|
||||||
|
t.Errorf("normalizeSetFilePath() = %v, want %v", result, tt.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue