Ensure nil is accepted as FS config (#1182)

In previous releases, passing a `nil` value as an FS config
did not cause any error. However, in 1.0.0-rc.1 this leads
to the creation of an invalid `adapter{fs: nil}`, which
eventually leads to a panic (nil):

    (f *FileEntry) Stat(st *platform.Stat_t) =>
        (r *lazyDir) file() =>
            r.fs.OpenFile(".", os.O_RDONLY, 0)

with fs == nil

The backwards-compatible fix is to make Adapt()
return UnimplementedFS, and ensuring `nil` is a valid value
that config is able to handle.

However, we may want to consider returning an error somewhere,
because configuring a nil FS may be unintended.

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
Edoardo Vacchi
2023-03-03 03:01:31 +01:00
committed by GitHub
parent 4043d58287
commit f36d30b82d
5 changed files with 37 additions and 1 deletions

View File

@@ -35,6 +35,11 @@ func TestFSConfig(t *testing.T) {
input: base.WithFSMount(testFS, "/").WithFSMount(testFS2, "/"),
expected: sysfs.Adapt(testFS2),
},
{
name: "WithFsMount nil",
input: base.WithFSMount(nil, "/"),
expected: sysfs.UnimplementedFS{},
},
{
name: "WithDirMount overwrites",
input: base.WithFSMount(testFS, "/").WithDirMount(".", "/"),