]> Cypherpunks repositories - gostls13.git/commit
os: avoid nil returns from Readdirnames, Readdir, ReadDir
authorRuss Cox <rsc@golang.org>
Wed, 4 Nov 2020 11:55:59 +0000 (06:55 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 4 Nov 2020 21:17:01 +0000 (21:17 +0000)
commitf532f19d94365d803e68568eb82d0dd19c81cc5b
tree9a7c7afac9652a4bcff6a5e9a67ed5dc092e9f3c
parente4b4e4b733624a4922741f13dcdaa493c01fe9fd
os: avoid nil returns from Readdirnames, Readdir, ReadDir

The refactoring of this code while adding ReadDir stopped
pre-allocating a 100-entry slice for the results.
That seemed like a good idea in general, since many
directories have nowhere near 100 entries, but it had the
side effect of returning a nil slice for an empty directory.

Some “golden” tests that are too sensitive about nil vs not
inside Google broke because Readdirnames(-1) was now
returning nil instead of []string{} on an empty directory.
It seems likely there are other such tests in the wild, and
it doesn't seem worth breaking them.

This commit restores the non-nil-ness of the old result,
without restoring the excessive preallocation.

Fixes #42367.

Change-Id: I2be72030ac703346e859a97c2d4e456fadfce9b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/267637
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/os/dir.go
src/os/os_test.go