diff --git a/src/remote/fs/fs.go b/src/remote/fs/fs.go index a26d89fb68..c239bac1a6 100644 --- a/src/remote/fs/fs.go +++ b/src/remote/fs/fs.go @@ -186,8 +186,8 @@ type dir struct { *info } -// ReadDir is a slightly incorrect implementation of ReadDir. It deviates slightly as it will report all files have 0 -// size. This seems to work for our limited purposes though. +// ReadDir implements listing the contents of a directory stored in the CAS. This is entirely based off the original +// data from the Tree proto so doesn't do any additional fetching. func (p *dir) ReadDir(n int) ([]iofs.DirEntry, error) { dirSize := n if n <= 0 { diff --git a/src/remote/fs/fs_test.go b/src/remote/fs/fs_test.go index 31889b75c1..25d07593ed 100644 --- a/src/remote/fs/fs_test.go +++ b/src/remote/fs/fs_test.go @@ -13,6 +13,8 @@ import ( "github.com/stretchr/testify/require" ) +var fooContent = "wibble wibble wibble" + type fakeClient struct { results map[digest.Digest][]byte } @@ -39,8 +41,7 @@ func newDigest(str string) digest.Digest { // |- badlink (a symlink to ../../foo which is root/.. i.e. invalid) func getTree(t *testing.T) (*fakeClient, *pb.Tree) { t.Helper() - - fooDigest := newDigest("foo") + fooDigest := newDigest(fooContent) foo := &pb.FileNode{ Name: "foo", @@ -120,7 +121,7 @@ func getTree(t *testing.T) (*fakeClient, *pb.Tree) { fc := &fakeClient{ results: map[digest.Digest][]byte{ - fooDigest: []byte("wibble wibble wibble"), + fooDigest: []byte(fooContent), }, } tree := &pb.Tree{ @@ -146,6 +147,9 @@ func TestReadDir(t *testing.T) { require.NoError(t, err) // We set them all to 0777 above assert.Equal(t, iofs.FileMode(0777), i.Mode(), "%v mode was wrong", e.Name()) + if e.Name() == "foo" { + assert.Equal(t, len([]byte(fooContent)), int(i.Size())) + } } entries, err = iofs.ReadDir(fs, ".")