Go version
go version go1.25.0 windows/amd64
Output of go env
in your module/workspace:
AR=ar
CC=gcc
CGO_CFLAGS=-O2 -g
CGO_CPPFLAGS=
CGO_CXXFLAGS=-O2 -g
CGO_ENABLED=1
CGO_FFLAGS=-O2 -g
CGO_LDFLAGS=-O2 -g
CXX=g++
GCCGO=gccgo
GO111MODULE=
GOAMD64=v1
GOARCH=amd64
GOAUTH=netrc
GOBIN=
GOCACHE=C:\Users\runneradmin\AppData\Local\go-build
GOCACHEPROG=
GODEBUG=
GOENV=C:\Users\runneradmin\AppData\Roaming\go\env
GOEXE=.exe
GOEXPERIMENT=
GOFIPS140=off
GOFLAGS=
GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\RUNNER~1\AppData\Local\Temp\go-build2877138821=/tmp/go-build -gno-record-gcc-switches
GOHOSTARCH=amd64
GOHOSTOS=windows
GOINSECURE=
GOMOD=D:\a\tracktools\tracktools\go.mod
GOMODCACHE=C:\Users\runneradmin\go\pkg\mod
GONOPROXY=
GONOSUMDB=
GOOS=windows
GOPATH=C:\Users\runneradmin\go
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOROOT=C:\hostedtoolcache\windows\go\1.25.0\x64
GOSUMDB=sum.golang.org
GOTELEMETRY=local
GOTELEMETRYDIR=C:\Users\runneradmin\AppData\Roaming\go\telemetry
GOTMPDIR=
GOTOOLCHAIN=auto
GOTOOLDIR=C:\hostedtoolcache\windows\go\1.25.0\x64\pkg\tool\windows_amd64
GOVCS=
GOVERSION=go1.25.0
GOWORK=
PKG_CONFIG=pkg-config
What did you do?
Call os.ReadDir on a file entry, Linux and Mac both return nil, syscall.ENOTDIR
but Windows returns []fs.DirEntry{}, syscall.ENOTDIR
.
In previous versions of go (v1.22) all platforms returned []fs.DirEntry{}, syscall.ENOTDIR
package main
import (
"io/fs"
"os"
"syscall"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_ReadDir(t *testing.T) {
tf, err := os.CreateTemp(t.TempDir(), "os-test")
require.NoError(t, err)
name := tf.Name()
require.NoError(t, tf.Close())
dirs, err := os.ReadDir(name)
require.ErrorIs(t, err, syscall.ENOTDIR)
var expectedDirs []fs.DirEntry
require.Equal(t, expectedDirs, dirs)
}
Result is:
osfs_test.go:23:
Error Trace: osfs_test.go:23
Error: Not equal:
expected: []fs.DirEntry(nil)
actual : []fs.DirEntry{}
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,3 @@
-([]fs.DirEntry) <nil>
+([]fs.DirEntry) {
+}
Test: Test_ReadDir
What did you see happen?
Windows returned []fs.DirEntry{}, syscall.ENOTDIR
What did you expect to see?
Consistent behaviour between all operating systems, Linux and Mac both return nil, syscall.ENOTDIR
but Windows returns []fs.DirEntry{}, syscall.ENOTDIR
.
Comment From: gabyhelp
Related Issues
- os: ReadDir on regular file returns ERROR_PATH_NOT_FOUND instead of ENOTDIR #46734
- os: ReadFile on directories does not return EISDIR in windows #43322
- os: `ReadDir` fails on file systems without File ID support on Windows #61907 (closed)
- os: ReadDir(`\.\pipe\`) fails with go1.21 on Windows #61918 (closed)
- io/fs,os: fs.ReadDir with an os.DirFS can produce invalid paths #44166 (closed)
- os: os.DirFS doesn't work with Windows UNC paths #54694 (closed)
- os: ReadDir("\tsclient\d\") fails with go1.21 on Windows #62044 (closed)
- os: document that fs.ReadDirFile.ReadDir doesn't restart each time #69301 (closed)
- os: Stat() returns inconsistent error on Windows #29119 (closed)
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: cherrymui
cc @golang/windows
Comment From: qmuntal
Thanks for reporting, fix incoming.
Comment From: gopherbot
Change https://go.dev/cl/699375 mentions this issue: os: return nil slice when ReadDir is used with a file on file_windows