8784: Fix error returned by Readdir() when count > remain.
authorTom Clegg <tom@curoverse.com>
Wed, 14 Jun 2017 20:05:39 +0000 (16:05 -0400)
committerTom Clegg <tom@curoverse.com>
Wed, 14 Jun 2017 20:05:39 +0000 (16:05 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curoverse.com>

sdk/go/arvados/collection_fs.go
sdk/go/arvados/collection_fs_test.go

index 01d5b65eb2f13257c8dfe0b2efa1cc2dea654391..89b296e3b527facfe8a14f81e8d055dbb3de5ef0 100644 (file)
@@ -61,11 +61,13 @@ func (cd *collectionDir) Readdir(count int) ([]os.FileInfo, error) {
        } else if len(ret) == 0 {
                return nil, io.EOF
        }
-       if count > len(ret) {
+       var err error
+       if count >= len(ret) {
                count = len(ret)
+               err = io.EOF
        }
        cd.dirents = cd.dirents[count:]
-       return ret[:count], nil
+       return ret[:count], err
 }
 
 // Stat implements os.File.
index 8cfd21e357773803d0f0a9ccf26dc60d71a8af69..7e8588b85e6769b9ea3814b1f2afdd7615b38c88 100644 (file)
@@ -45,15 +45,22 @@ func (s *CollectionFSSuite) TestReaddirFull(c *check.C) {
 func (s *CollectionFSSuite) TestReaddirLimited(c *check.C) {
        f, err := s.fs.Open("./dir1")
        c.Assert(err, check.IsNil)
-       for i := 0; i < 2; i++ {
-               fis, err := f.Readdir(1)
-               c.Check(err, check.IsNil)
-               c.Check(len(fis), check.Equals, 1)
-               if len(fis) > 0 {
-                       c.Check(fis[0].Size(), check.Equals, int64(3))
-               }
-       }
+
        fis, err := f.Readdir(1)
+       c.Check(err, check.IsNil)
+       c.Check(len(fis), check.Equals, 1)
+       if len(fis) > 0 {
+               c.Check(fis[0].Size(), check.Equals, int64(3))
+       }
+
+       fis, err = f.Readdir(1)
+       c.Check(err, check.Equals, io.EOF)
+       c.Check(len(fis), check.Equals, 1)
+       if len(fis) > 0 {
+               c.Check(fis[0].Size(), check.Equals, int64(3))
+       }
+
+       fis, err = f.Readdir(1)
        c.Check(len(fis), check.Equals, 0)
        c.Check(err, check.NotNil)
        c.Check(err, check.Equals, io.EOF)
@@ -65,7 +72,7 @@ func (s *CollectionFSSuite) TestReaddirLimited(c *check.C) {
        c.Assert(err, check.IsNil)
        fis, err = f.Readdir(2)
        c.Check(len(fis), check.Equals, 1)
-       c.Assert(err, check.IsNil)
+       c.Assert(err, check.Equals, io.EOF)
        fis, err = f.Readdir(2)
        c.Check(len(fis), check.Equals, 0)
        c.Assert(err, check.Equals, io.EOF)