Skip to content

Commit

Permalink
Merge pull request #268 from hasheddan/tarfs-panic
Browse files Browse the repository at this point in the history
Do not panic on passing empty tar reader to tarfs
  • Loading branch information
0xmichalis committed Oct 6, 2020
2 parents a4ea980 + 9fa7c3b commit efa411e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tarfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions tarfs/tarfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"syscall"
"testing"

Expand Down Expand Up @@ -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())
}

Expand Down

0 comments on commit efa411e

Please sign in to comment.