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]
|
||||
|
||||
if StripPrefixesAndTrailingSlash(guestPath) == "" {
|
||||
// Default to bind to '/' when guestPath is effectively empty.
|
||||
guestPath = "/"
|
||||
c.fsc.rootFS = fs
|
||||
}
|
||||
c.fsc.openedFiles.Insert(&FileEntry{
|
||||
|
||||
@@ -3,6 +3,7 @@ package sys
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
@@ -55,8 +56,10 @@ func TestNewFSContext(t *testing.T) {
|
||||
tc := tt
|
||||
|
||||
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{}
|
||||
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)
|
||||
fsc := c.fsc
|
||||
defer fsc.Close()
|
||||
@@ -86,6 +89,9 @@ func TestNewFSContext(t *testing.T) {
|
||||
require.Equal(t, f1, f2)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSContext_CloseFile(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user