Skip to content

Commit 3cbb041

Browse files
authored
fix: filepaths not correctly resolved on Windows (#1229)
The [path](https://pkg.go.dev/path) package only supports slash-separated paths. We should use [filepath](https://pkg.go.dev/path/filepath) for platform-specific path handling instead. Fixes #1225
1 parent 5b70819 commit 3cbb041

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

internal/scripts/generate_docs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6-
"path"
6+
"path/filepath"
77
"regexp"
88
"strings"
99

@@ -56,18 +56,18 @@ func run() error {
5656
if f.IsDir() {
5757
continue
5858
}
59-
filepath := path.Join(dir, f.Name())
60-
bytes, err := os.ReadFile(filepath)
59+
path := filepath.Join(dir, f.Name())
60+
bytes, err := os.ReadFile(path)
6161
if err != nil {
62-
return fmt.Errorf("could not read file at %q: %w", filepath, err)
62+
return fmt.Errorf("could not read file at %q: %w", path, err)
6363
}
6464
bytes = generatedOnRegex.ReplaceAll(bytes, nil)
6565
// We do this to wrap tables in a code block. Otherwise, they won't be displayed properly in markdown viewers.
6666
bytes = []byte(strings.ReplaceAll(string(bytes), "┌", "```\n┌"))
6767
bytes = []byte(strings.ReplaceAll(string(bytes), "┘", "┘\n```"))
68-
err = os.WriteFile(filepath, bytes, f.Type())
68+
err = os.WriteFile(path, bytes, f.Type())
6969
if err != nil {
70-
return fmt.Errorf("could not write file at %q: %w", filepath, err)
70+
return fmt.Errorf("could not write file at %q: %w", path, err)
7171
}
7272
}
7373

internal/state/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"io"
88
"os"
9-
"path"
9+
"path/filepath"
1010
"strings"
1111

1212
"github.com/BurntSushi/toml"
@@ -201,7 +201,7 @@ func (cfg *config) Read(f any) error {
201201

202202
func (cfg *config) Write(w io.Writer) (err error) {
203203
if w == nil {
204-
dir := path.Dir(cfg.path)
204+
dir := filepath.Dir(cfg.path)
205205
if err = os.MkdirAll(dir, 0750); err != nil {
206206
return err
207207
}

0 commit comments

Comments
 (0)