From 20f4e1f12de3ddca906265b05a98fb5be2cd2122 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Tue, 2 Sep 2025 20:20:09 -0700 Subject: [PATCH 1/2] Use filepath.Path when handling directory names Signed-off-by: Evan Anderson --- pkg/action/install.go | 3 +-- pkg/cmd/template.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index 0fe3ebc4b..79acc8c7d 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -26,7 +26,6 @@ import ( "log/slog" "net/url" "os" - "path" "path/filepath" "strings" "sync" @@ -677,7 +676,7 @@ func createOrOpenFile(filename string, appendData bool) (*os.File, error) { // check if the directory exists to create file. creates if doesn't exist func ensureDirectoryForFile(file string) error { - baseDir := path.Dir(file) + baseDir := filepath.Dir(file) _, err := os.Stat(baseDir) if err != nil && !errors.Is(err, fs.ErrNotExist) { return err diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 81c112d51..59c24f39e 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -23,7 +23,6 @@ import ( "io" "io/fs" "os" - "path" "path/filepath" "regexp" "slices" @@ -250,7 +249,7 @@ func createOrOpenFile(filename string, appendData bool) (*os.File, error) { } func ensureDirectoryForFile(file string) error { - baseDir := path.Dir(file) + baseDir := filepath.Dir(file) _, err := os.Stat(baseDir) if err != nil && !errors.Is(err, fs.ErrNotExist) { return err From a493d442e460db5d7ef162963889dbdf09b3a055 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Wed, 3 Sep 2025 11:19:34 -0700 Subject: [PATCH 2/2] Use consistent slashes whether expanded on Windows or POSIX Signed-off-by: Evan Anderson --- pkg/action/action.go | 6 +++--- pkg/action/install.go | 3 ++- pkg/cmd/get_hooks.go | 3 ++- pkg/cmd/status.go | 3 ++- pkg/cmd/template.go | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/action/action.go b/pkg/action/action.go index bcf6ca8ef..a5a829f93 100644 --- a/pkg/action/action.go +++ b/pkg/action/action.go @@ -281,7 +281,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, if strings.TrimSpace(content) == "" { continue } - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", name, content) + fmt.Fprintf(b, "---\n# Source: %s\n%s\n", filepath.ToSlash(name), content) } return hs, b, "", err } @@ -292,7 +292,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, if includeCrds { for _, crd := range ch.CRDObjects() { if outputDir == "" { - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", crd.Filename, string(crd.File.Data[:])) + fmt.Fprintf(b, "---\n# Source: %s\n%s\n", filepath.ToSlash(crd.Filename), string(crd.File.Data[:])) } else { err = writeToFile(outputDir, crd.Filename, string(crd.File.Data[:]), fileWritten[crd.Filename]) if err != nil { @@ -308,7 +308,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values, if hideSecret && m.Head.Kind == "Secret" && m.Head.Version == "v1" { fmt.Fprintf(b, "---\n# Source: %s\n# HIDDEN: The Secret output has been suppressed\n", m.Name) } else { - fmt.Fprintf(b, "---\n# Source: %s\n%s\n", m.Name, m.Content) + fmt.Fprintf(b, "---\n# Source: %s\n%s\n", filepath.ToSlash(m.Name), m.Content) } } else { newDir := outputDir diff --git a/pkg/action/install.go b/pkg/action/install.go index 79acc8c7d..51a7fb2db 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -657,7 +657,8 @@ func writeToFile(outputDir string, name string, data string, appendData bool) er defer f.Close() - _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", name, data) + // Use consistent (POSIX) filepaths in comments, even if expanded on Windows. + _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", filepath.ToSlash(name), data) if err != nil { return err diff --git a/pkg/cmd/get_hooks.go b/pkg/cmd/get_hooks.go index 7ffefd93c..a102410b0 100644 --- a/pkg/cmd/get_hooks.go +++ b/pkg/cmd/get_hooks.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "log" + "path/filepath" "github.com/spf13/cobra" @@ -53,7 +54,7 @@ func newGetHooksCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } for _, hook := range res.Hooks { - fmt.Fprintf(out, "---\n# Source: %s\n%s\n", hook.Path, hook.Manifest) + fmt.Fprintf(out, "---\n# Source: %s\n%s\n", filepath.ToSlash(hook.Path), hook.Manifest) } return nil }, diff --git a/pkg/cmd/status.go b/pkg/cmd/status.go index 3d1309c3e..619557ee9 100644 --- a/pkg/cmd/status.go +++ b/pkg/cmd/status.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "log" + "path/filepath" "strings" "time" @@ -214,7 +215,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error { if strings.EqualFold(s.release.Info.Description, "Dry run complete") || s.debug { _, _ = fmt.Fprintln(out, "HOOKS:") for _, h := range s.release.Hooks { - _, _ = fmt.Fprintf(out, "---\n# Source: %s\n%s\n", h.Path, h.Manifest) + _, _ = fmt.Fprintf(out, "---\n# Source: %s\n%s\n", filepath.ToSlash(h.Path), h.Manifest) } _, _ = fmt.Fprintf(out, "MANIFEST:\n%s\n", s.release.Manifest) } diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index 59c24f39e..2ea6bd51f 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -115,7 +115,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { continue } if client.OutputDir == "" { - fmt.Fprintf(&manifests, "---\n# Source: %s\n%s\n", m.Path, m.Manifest) + fmt.Fprintf(&manifests, "---\n# Source: %s\n%s\n", filepath.ToSlash(m.Path), m.Manifest) } else { newDir := client.OutputDir if client.UseReleaseName { @@ -231,7 +231,7 @@ func writeToFile(outputDir string, name string, data string, appendData bool) er defer f.Close() - _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", name, data) + _, err = fmt.Fprintf(f, "---\n# Source: %s\n%s\n", filepath.ToSlash(name), data) if err != nil { return err