Skip to content

os: on windows RemoveAll removing directories containing read-only files errors with unlinkat ... Access is denied #75922

@rheilek

Description

@rheilek

Go version

go version go1.25.2 linux/amd64

Output of go env in your module/workspace:

R='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='/home/rheilek/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/rheilek/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2507944389=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/rheilek/development/go/src/gitlab.siv.de/middleware/agent/go.mod'
GOMODCACHE='/home/rheilek/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/rheilek/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/rheilek/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

In our projects, we create marker files with read-only permissions. Afterwards, we remove the entire directory. Since 2015, the code has not changed. However, after upgrading to Go 1.25.2, we are now encountering the error "Access is denied."

The code is cross-compiled for Linux and Windows. The error only occurs under windows.

What did you see happen?

Code to reproduce on windows

_ = os.Mkdir("dir", 0700)
_ = os.WriteFile("dir/test", []byte(`1`), 0400) // read-only file
fmt.Println(os.RemoveAll("dir"))

stdout with go 1.25.2

unlinkat .\dir\test: Access is denied.

stdout with go 1.24.9

<nil>

What did you expect to see?

Remove of the whole diretory - error is nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions