diff --git a/tarfs/fs.go b/tarfs/fs.go index ba3212bf..f8a2ce27 100644 --- a/tarfs/fs.go +++ b/tarfs/fs.go @@ -63,6 +63,9 @@ func New(t *tar.Reader) *Fs { } + if fs.files[afero.FilePathSeparator] == nil { + fs.files[afero.FilePathSeparator] = make(map[string]*File) + } // Add a pseudoroot fs.files[afero.FilePathSeparator][""] = &File{ h: &tar.Header{ diff --git a/tarfs/tarfs_test.go b/tarfs/tarfs_test.go index 8d5eaab7..c588c792 100644 --- a/tarfs/tarfs_test.go +++ b/tarfs/tarfs_test.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "reflect" + "strings" "syscall" "testing" @@ -54,6 +55,9 @@ func TestMain(m *testing.M) { tfs := New(tar.NewReader(tf)) afs = &afero.Afero{Fs: tfs} + + // Check that an empty reader does not panic. + _ = New(tar.NewReader(strings.NewReader(""))) os.Exit(m.Run()) }