You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The os.File.Readdir(-1) function returns an error and stops reading the contents of the directory on the first failure to Lstat an object in the directory. This is confusing since the os.File.Readdir(-1) function will still return the items in the directory that it had already gotten a status without an error.
This is happening to me when os.File.Readdir(-1) encounters a file in a directory that it does not have permission to stat. It rightly returns http: error reading directory: lstat 'full file path': permission denied, but I would expect it to continue iterating over the remaining files in the directory.
What did you expect to see?
I expected to see all of the items (files, links, directories, etc) in the directory being read that can be stated without error.
What did you see instead?
Only the files before the first error were returned. Any remaining files that would have been read without error were omitted.
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
file.Readdir(-1) stops reading on first file error
os: file.Readdir(-1) stops reading on first file error
Mar 28, 2018
This behavior is explicitly documented. The workaround is to use Readdirnames. Since it's been documented this way since Go 1, we aren't going to change it now.
The problem is that many internal functions, such as the http.FileServer use os.File.Readdir(-1), which was my use case. In this case, I either have to completely make my own version of http.FileServer, or fix it here.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN="/home/fisherb/go/bin"
GOCACHE="/home/fisherb/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/fisherb/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build933376266=/tmp/go-build -gno-record-gcc-switches"
What did you do?
The os.File.Readdir(-1) function returns an error and stops reading the contents of the directory on the first failure to Lstat an object in the directory. This is confusing since the os.File.Readdir(-1) function will still return the items in the directory that it had already gotten a status without an error.
This is happening to me when os.File.Readdir(-1) encounters a file in a directory that it does not have permission to stat. It rightly returns
http: error reading directory: lstat 'full file path': permission denied
, but I would expect it to continue iterating over the remaining files in the directory.What did you expect to see?
I expected to see all of the items (files, links, directories, etc) in the directory being read that can be stated without error.
What did you see instead?
Only the files before the first error were returned. Any remaining files that would have been read without error were omitted.
The text was updated successfully, but these errors were encountered: