mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/file: bug fix: VirtualFS.Open(".") should always return a new entry
Closes #3081
This commit is contained in:
parent
81d89e15d8
commit
e43bb3898b
@ -29,15 +29,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VirtualFS struct {
|
type VirtualFS struct {
|
||||||
root virtualFSRoot
|
paths []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVirtualFS(paths []string) *VirtualFS {
|
func NewVirtualFS(paths []string) *VirtualFS {
|
||||||
fs := &VirtualFS{}
|
fs := &VirtualFS{}
|
||||||
fs.root.addRealPaths(paths)
|
fs.paths = make([]string, len(paths))
|
||||||
|
copy(fs.paths, paths)
|
||||||
return fs
|
return fs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *VirtualFS) newRootFS() *virtualFSRoot {
|
||||||
|
var root virtualFSRoot
|
||||||
|
root.addRealPaths(v.paths)
|
||||||
|
return &root
|
||||||
|
}
|
||||||
|
|
||||||
func (v *VirtualFS) Open(name string) (fs.File, error) {
|
func (v *VirtualFS) Open(name string) (fs.File, error) {
|
||||||
if !fs.ValidPath(name) {
|
if !fs.ValidPath(name) {
|
||||||
return nil, &fs.PathError{
|
return nil, &fs.PathError{
|
||||||
@ -48,15 +55,16 @@ func (v *VirtualFS) Open(name string) (fs.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if name == "." {
|
if name == "." {
|
||||||
return &v.root, nil
|
return v.newRootFS(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// A valid path must not include a token "." or "..", except for "." itself.
|
// A valid path must not include a token "." or "..", except for "." itself.
|
||||||
es := strings.Split(name, "/")
|
es := strings.Split(name, "/")
|
||||||
for _, realPath := range v.root.realPaths {
|
for _, realPath := range v.paths {
|
||||||
if filepath.Base(realPath) != es[0] {
|
if filepath.Base(realPath) != es[0] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// TODO: Does this work on Windows?
|
||||||
return os.Open(filepath.Join(append([]string{realPath}, es[1:]...)...))
|
return os.Open(filepath.Join(append([]string{realPath}, es[1:]...)...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user