Compare commits

..

1 Commits

Author SHA1 Message Date
Bertrand Jung
b541855ee7
Merge 1dd96726c4 into 81d89e15d8 2024-09-05 21:11:11 +02:00
2 changed files with 6 additions and 23 deletions

View File

@ -29,22 +29,15 @@ import (
)
type VirtualFS struct {
paths []string
root virtualFSRoot
}
func NewVirtualFS(paths []string) *VirtualFS {
fs := &VirtualFS{}
fs.paths = make([]string, len(paths))
copy(fs.paths, paths)
fs.root.addRealPaths(paths)
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) {
if !fs.ValidPath(name) {
return nil, &fs.PathError{
@ -55,17 +48,15 @@ func (v *VirtualFS) Open(name string) (fs.File, error) {
}
if name == "." {
return v.newRootFS(), nil
return &v.root, nil
}
// A valid path must not include a token "." or "..", except for "." itself.
es := strings.Split(name, "/")
for _, realPath := range v.paths {
for _, realPath := range v.root.realPaths {
if filepath.Base(realPath) != es[0] {
continue
}
// os.File should implement fs.File interface, so this should be fine even on Windows.
// See https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/os/file.go;l=695-710
return os.Open(filepath.Join(append([]string{realPath}, es[1:]...)...))
}

View File

@ -221,11 +221,7 @@ type writePixelsCommandArgs struct {
}
func (c *writePixelsCommand) String() string {
var args []string
for _, a := range c.args {
args = append(args, fmt.Sprintf("region: %s", a.region.String()))
}
return fmt.Sprintf("write-pixels: dst: %d, args: %s", c.dst.id, strings.Join(args, ", "))
return fmt.Sprintf("write-pixels: dst: %d, len(args): %d", c.dst.id, len(c.args))
}
// Exec executes the writePixelsCommand.
@ -274,11 +270,7 @@ func (c *readPixelsCommand) NeedsSync() bool {
}
func (c *readPixelsCommand) String() string {
var args []string
for _, a := range c.args {
args = append(args, fmt.Sprintf("region: %s", a.Region.String()))
}
return fmt.Sprintf("read-pixels: image: %d, args: %v", c.img.id, strings.Join(args, ", "))
return fmt.Sprintf("read-pixels: image: %d", c.img.id)
}
// disposeImageCommand represents a command to dispose an image.