Skip to content

Commit

Permalink
Normalize paths to fix EFS support on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Dec 5, 2018
1 parent 37480b0 commit 50f2220
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions xio/fs/embedded/efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ func (f *efs) IsLive() bool {
return false
}

func (f *efs) actualPath(path string) string {
fmt.Println(filepath.ToSlash(filepath.Clean("/" + path)))
return filepath.ToSlash(filepath.Clean("/" + path))
}

func (f *efs) Open(path string) (http.File, error) {
path = filepath.Clean("/" + path)
one, ok := f.files[path]
one, ok := f.files[f.actualPath(path)]
if !ok {
return nil, os.ErrNotExist
}
Expand All @@ -42,7 +46,7 @@ func (f *efs) Open(path string) (http.File, error) {
}

func (f *efs) ContentAsBytes(path string) ([]byte, bool) {
if one, ok := f.files[filepath.Clean("/"+path)]; ok {
if one, ok := f.files[f.actualPath(path)]; ok {
if err := one.uncompressData(); err != nil {
return nil, false
}
Expand Down
12 changes: 6 additions & 6 deletions xio/fs/embedded/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ func NewEFS(files map[string]*File) *EFS {
for k, v := range files {
dir, _ := filepath.Split(k)
dir = filepath.Clean(dir)
di, ok := dirs[dir]
di, ok := dirs[filepath.ToSlash(dir)]
if !ok {
di = &dinfo{
f: &File{
name: filepath.Base(dir),
name: filepath.ToSlash(filepath.Base(dir)),
modTime: now,
isDir: true,
},
m: collection.NewStringSet(),
}
dirs[dir] = di
dirs[filepath.ToSlash(dir)] = di
}
di.f.files = append(di.f.files, v)
// Ensure parents are present
Expand All @@ -62,17 +62,17 @@ func NewEFS(files map[string]*File) *EFS {
break
}
dir = filepath.Clean(dir)
p, ok := dirs[dir]
p, ok := dirs[filepath.ToSlash(dir)]
if !ok {
p = &dinfo{
f: &File{
name: filepath.Base(dir),
name: filepath.ToSlash(filepath.Base(dir)),
modTime: now,
isDir: true,
},
m: collection.NewStringSet(),
}
dirs[dir] = p
dirs[filepath.ToSlash(dir)] = p
}
if p.m.Contains(path) {
break
Expand Down

0 comments on commit 50f2220

Please sign in to comment.