fs: empty guest path should bind to / (#1565)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
Edoardo Vacchi
2023-07-07 01:10:01 +02:00
committed by GitHub
parent 2c21f3aa8f
commit affca16f15
2 changed files with 34 additions and 26 deletions

View File

@@ -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{

View File

@@ -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) {