forked from mirror/afero
Do not panic on passing empty tar reader to tarfs
Corrects a bug where passing an empty tar reader to tarfs would cause adding the pseudoroot to panic with assignment to entry in nil map. Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
parent
a4ea980f2d
commit
9fa7c3b3c6
|
@ -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{
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue