]> Cypherpunks repositories - gostls13.git/commitdiff
os: remove unused variable in unix implementation of File.readdir
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 4 Nov 2020 19:52:43 +0000 (11:52 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 5 Nov 2020 16:20:01 +0000 (16:20 +0000)
Change-Id: I0dd8a325bce6ed12d1ec1dc206ded62398925aef
Reviewed-on: https://go-review.googlesource.com/c/go/+/267758
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>

src/os/dir_unix.go

index 3e5a6983501ee91a5dca1de9abfc223b1e0eb0ec..0e1eab1c965ee5c7eea49f6e6133c18a752a4357 100644 (file)
@@ -36,9 +36,16 @@ func (f *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEn
        }
        d := f.dirinfo
 
-       size := n
-       if size <= 0 {
-               size = 100
+       // Change the meaning of n for the implementation below.
+       //
+       // The n above was for the public interface of "if n <= 0,
+       // Readdir returns all the FileInfo from the directory in a
+       // single slice".
+       //
+       // But below, we use only negative to mean looping until the
+       // end and positive to mean bounded, with positive
+       // terminating at 0.
+       if n == 0 {
                n = -1
        }
 
@@ -88,7 +95,9 @@ func (f *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEn
                if string(name) == "." || string(name) == ".." {
                        continue
                }
-               n--
+               if n > 0 { // see 'n == 0' comment above
+                       n--
+               }
                if mode == readdirName {
                        names = append(names, string(name))
                } else if mode == readdirDirEntry {