Not planned
Description
Go version
go version go1.23.2 windows/amd64
Output of go env
in your module/workspace:
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\sweh\AppData\Local\go-build
set GOENV=C:\Users\sweh\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\sweh\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\sweh\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.2
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\sweh\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\cygwin64\tmp\go-build1197283358=/tmp/go-build -gno-record-gcc-switches
What did you do?
Windows typically doesn't allow for files or directories ending in a "." and attempts to do so will result in the final "." being removed. But not all subsystems obey this, so we can use cygwin
mkdir TEST TEST/a. TEST/b.
touch TEST/b./c
If we try to do a "walk" on this then errors are passed to the walk function, the info
field isn't populated, and the tree isn't fully recursed.
import (
"fmt"
"os"
"path/filepath"
)
func find_walk(path string, info os.FileInfo, err error) error {
fmt.Printf("Looking at %s\n", path)
if err != nil {
fmt.Printf("Error: %s\n", err)
// return err
}
// fmt.Printf("We found %s of size %d\n", path,info.Size())
return nil
}
func main() {
filepath.Walk("TEST", find_walk)
}
I suspect this is os.Lstat()
failing on Windows by calling the Win32 handler which can't support these files, even though the files can be created!
What did you see happen?
Looking at TEST
Looking at TEST\a.
Error: CreateFile TEST\a.: The system cannot find the file specified.
Looking at TEST\b.
Error: CreateFile TEST\b.: The system cannot find the file specified.
What did you expect to see?
The directory "b." should be recursed into but it's not because the Lstat()
is failing and so the function doesn't know it's a directory.
I'm not sure this is easily fixable!
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
gabyhelp commentedon Oct 7, 2024
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]path/filepath: can not handle files on windows that end , a .[/-][+]path/filepath: can not handle files on windows that end with a .[/+]ianlancetaylor commentedon Oct 7, 2024
CC @golang/windows
qmuntal commentedon Oct 8, 2024
Related to #54040.
qmuntal commentedon Oct 8, 2024
Windows file naming rules says that files and directories should not contain trailing spaces or periods:
In #54040 we agreed to not special case trailing spaces and periods, as it is not possible to (easily) fully support them using Win32 API calls. If someone really needs to operate with these non-compliant file paths, then Windows already provide an escape hatch: prepend the path with
\\?\
so the path is not validated nor mangled in any way.@sweharris, in your example you can change the main function to do the following: