Skip to content

Commit bc8384e

Browse files
committed
Fix compiler panics when building on Windows.
Embedded file systems use unix-style slashes, which was causing errors on Windows, when two styles were mixed. Converting all VFS paths to unix-style slashes resolves the issue. Fixes #1049.
1 parent 55d398a commit bc8384e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

build/vfs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"os"
77
"path"
8+
"path/filepath"
89
"strings"
910
)
1011

@@ -13,6 +14,7 @@ import (
1314
type vfs struct{ http.FileSystem }
1415

1516
func (fs vfs) IsDir(name string) bool {
17+
name = filepath.ToSlash(name)
1618
dir, err := fs.Open(name)
1719
if err != nil {
1820
return false
@@ -26,6 +28,7 @@ func (fs vfs) IsDir(name string) bool {
2628
}
2729

2830
func (fs vfs) ReadDir(name string) (fi []os.FileInfo, err error) {
31+
name = filepath.ToSlash(name)
2932
dir, err := fs.Open(name)
3033
if err != nil {
3134
return nil, err
@@ -35,6 +38,7 @@ func (fs vfs) ReadDir(name string) (fi []os.FileInfo, err error) {
3538
}
3639

3740
func (fs vfs) OpenFile(name string) (r io.ReadCloser, err error) {
41+
name = filepath.ToSlash(name)
3842
return fs.Open(name)
3943
}
4044

@@ -75,10 +79,12 @@ type withPrefix struct {
7579
}
7680

7781
func (wp *withPrefix) Open(name string) (http.File, error) {
78-
if !strings.HasPrefix(name, wp.prefix) {
82+
name = filepath.ToSlash(name)
83+
prefix := filepath.ToSlash(wp.prefix)
84+
if !strings.HasPrefix(name, prefix) {
7985
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
8086
}
81-
f, err := wp.fs.Open(strings.TrimPrefix(name, wp.prefix))
87+
f, err := wp.fs.Open(strings.TrimPrefix(name, prefix))
8288
if err != nil {
8389
return nil, &os.PathError{Op: "open", Path: name, Err: err}
8490
}

0 commit comments

Comments
 (0)