Skip to content

Commit 3c276a1

Browse files
authored
fix: readFile on windows (works cross-platform) (#1)
Using path instead of filepath fixes an issue on Windows where the template files could not be found. I tested these changes on macOS and Windows and they worked for me. ## Relevant docs: ### https://pkg.go.dev/embed ``` ... The path separator is a forward slash, even on Windows systems. ... ``` ### https://pkg.go.dev/path/filepath ``` The filepath package uses either forward slashes or backslashes, depending on the operating system. To process paths such as URLs that always use forward slashes regardless of the operating system, see the [path](https://pkg.go.dev/path) package. ```
1 parent 5a67d4d commit 3c276a1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package yaakcli
22

33
import (
44
"os"
5-
"path/filepath"
5+
"path"
66
"strings"
77
)
88

9-
func writeFile(path, contents string) {
10-
CheckError(os.MkdirAll(filepath.Dir(path), 0755))
11-
CheckError(os.WriteFile(path, []byte(contents), 0755))
9+
func writeFile(writePath, contents string) {
10+
CheckError(os.MkdirAll(path.Dir(writePath), 0755))
11+
CheckError(os.WriteFile(writePath, []byte(contents), 0755))
1212
}
1313

1414
func readFile(path string) string {
@@ -18,9 +18,9 @@ func readFile(path string) string {
1818
}
1919

2020
func copyFile(relPath, dstDir, name string) {
21-
contents := readFile(filepath.Join("template", relPath))
21+
contents := readFile(path.Join("template", relPath))
2222
contents = strings.ReplaceAll(contents, "yaak-plugin-name", name)
23-
writeFile(filepath.Join(dstDir, relPath), contents)
23+
writeFile(path.Join(dstDir, relPath), contents)
2424
}
2525

2626
func fileExists(path string) bool {

0 commit comments

Comments
 (0)