fs: empty guest path should bind to / (#1565)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
@@ -413,6 +413,8 @@ func (c *Context) InitFSContext(
|
|||||||
guestPath := guestPaths[i]
|
guestPath := guestPaths[i]
|
||||||
|
|
||||||
if StripPrefixesAndTrailingSlash(guestPath) == "" {
|
if StripPrefixesAndTrailingSlash(guestPath) == "" {
|
||||||
|
// Default to bind to '/' when guestPath is effectively empty.
|
||||||
|
guestPath = "/"
|
||||||
c.fsc.rootFS = fs
|
c.fsc.rootFS = fs
|
||||||
}
|
}
|
||||||
c.fsc.openedFiles.Insert(&FileEntry{
|
c.fsc.openedFiles.Insert(&FileEntry{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package sys
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -55,8 +56,10 @@ func TestNewFSContext(t *testing.T) {
|
|||||||
tc := tt
|
tc := tt
|
||||||
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
for _, root := range []string{"/", ""} {
|
||||||
|
t.Run(fmt.Sprintf("root = '%s'", root), func(t *testing.T) {
|
||||||
c := Context{}
|
c := Context{}
|
||||||
err := c.InitFSContext(nil, nil, nil, []fsapi.FS{tc.fs}, []string{"/"}, nil)
|
err := c.InitFSContext(nil, nil, nil, []fsapi.FS{tc.fs}, []string{root}, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fsc := c.fsc
|
fsc := c.fsc
|
||||||
defer fsc.Close()
|
defer fsc.Close()
|
||||||
@@ -86,6 +89,9 @@ func TestNewFSContext(t *testing.T) {
|
|||||||
require.Equal(t, f1, f2)
|
require.Equal(t, f1, f2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSContext_CloseFile(t *testing.T) {
|
func TestFSContext_CloseFile(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user