Skip to content

fs: ValidPath() docs seem to contradict test case regarding "." #70155

Closed as not planned
@mholt

Description

@mholt

Go version

go version go1.23.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/matt/.cache/go-build'
GOENV='/home/matt/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/matt/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/matt/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.2'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/matt/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/matt/Dev/archiver/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3734862726=/tmp/go-build -gno-record-gcc-switches'

What did you do?

func (f *ArchiveFS) Open(name string) (fs.File, error) {
	if !fs.ValidPath(name) {
		return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid}
	}

Trying to implement fs.FS with the use of fs.ValidName().

What did you see happen?

A path of ./foo is rejected, even though a file system literally has a root directory named ".", and the docs for fs.ValidPath() state (emphasis mine):

Path names must not contain an element that is “.” or “..” or the empty string, except for the special case that the root directory is named “.”.

Here, the root directory is named ".", and the docs say that should be an exception that is allowed. Yet the test case seems to show otherwise: {"./x", false},

What did you expect to see?

I might be reading the docs wrong, but it seems like this should be allowed, especially since there are virtual file systems (like a tar archive) where there are literally root directories named "." (this can happen apparently when a tar archive is created in the same directory it is archiving).

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions