Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions internal/tarfs/tarfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ package tarfs
import (
"archive/tar"
"bufio"
"cmp"
"errors"
"fmt"
"io"
"io/fs"
"path"
"slices"
"sync"
"time"
)
Expand Down Expand Up @@ -98,7 +96,6 @@ type FS struct {
ra io.ReaderAt
files []*Entry
index map[string]int
dirs map[string][]fs.DirEntry
}

func (fsys *FS) Readlink(name string) (string, error) {
Expand Down Expand Up @@ -184,15 +181,6 @@ func (fsys *FS) Stat(name string) (fs.FileInfo, error) {
return nil, fs.ErrNotExist
}

func (fsys *FS) ReadDir(name string) ([]fs.DirEntry, error) {
dirs, ok := fsys.dirs[name]
if !ok {
return []fs.DirEntry{}, nil
}

return dirs, nil
}

type countReader struct {
r io.Reader
n int64
Expand All @@ -209,12 +197,8 @@ func New(ra io.ReaderAt, size int64) (*FS, error) {
ra: ra,
files: []*Entry{},
index: map[string]int{},
dirs: map[string][]fs.DirEntry{},
}

// Number of entries in a given directory, so we know how large of a slice to allocate.
dirCount := map[string]int{}

// TODO: Consider caching this across builds.
r := io.NewSectionReader(ra, 0, size)

Expand All @@ -239,24 +223,6 @@ func New(ra io.ReaderAt, size int64) (*FS, error) {
dir: dir,
fi: hdr.FileInfo(),
})

dirCount[dir]++
}

// Pre-generate the results of ReadDir so we don't allocate a ton if fs.WalkDir calls us.
// TODO: Consider doing this lazily in a sync.Once the first time we see a ReadDir.
for dir, count := range dirCount {
fsys.dirs[dir] = make([]fs.DirEntry, 0, count)
}

for _, f := range fsys.files {
fsys.dirs[f.dir] = append(fsys.dirs[f.dir], f)
}

for _, files := range fsys.dirs {
slices.SortFunc(files, func(a, b fs.DirEntry) int {
return cmp.Compare(a.Name(), b.Name())
})
}

return fsys, nil
Expand Down
Loading