Skip to content

embed: Files starting with : (double dots) are not embedded (undocumented behavior) #46199

@reddec

Description

@reddec

What version of Go are you using (go version)?

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/baryshnikov/.cache/go-build"
GOENV="/home/baryshnikov/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/baryshnikov/Develop/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/baryshnikov/Develop/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/latest"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/latest/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build1338096382=/tmp/go-build -gno-record-gcc-switches"

What did you do?

demo-fs.tar.gz

Source code (see attachment)
package main

import (
"embed"
"fmt"
"os"
)

//go:embed assets
var assets embed.FS

func main() {
files := []string{
"assets/root.txt",
"assets/:normal",
"assets/:alsonormal/file2.txt",
}

// check in real file system
for _, file := range files {
	_, err := os.Open(file)
	if err != nil {
		fmt.Println("[FAILED ] failed open", file, "in real file system:", err)
	} else {
		fmt.Println("[SUCCESS] open", file, "in real file system")
	}
}

// check in embedded
for _, file := range files {
	_, err := assets.Open(file)
	if err != nil {
		fmt.Println("[FAILED ] failed open", file, "in embedded file system", ":", err)
	} else {
		fmt.Println("[SUCCESS] open", file, "in embedded file system")
	}
}

}

What did you expect to see?

Embedded files with : in names were included.

(from demo)

[SUCCESS] open assets/root.txt in real file system
[SUCCESS] open assets/:normal in real file system
[SUCCESS] open assets/:alsonormal/file2.txt in real file system
[SUCCESS] open assets/root.txt in embedded file system
[SUCCESS] open assets/:normal in embedded file system
[SUCCESS] open assets/:alsonormal/file2.txt in embedded file system

What did you see instead?

Embedded files with : in names were not included.

(from demo)

[SUCCESS] open assets/root.txt in real file system
[SUCCESS] open assets/:normal in real file system
[SUCCESS] open assets/:alsonormal/file2.txt in real file system
[SUCCESS] open assets/root.txt in embedded file system
[FAILED ] failed open assets/:normal in embedded file system : open assets/:normal: file does not exist
[FAILED ] failed open assets/:alsonormal/file2.txt in embedded file system : open assets/:alsonormal/file2.txt: file does not exist

Analysis

Likely related to #45447.
Embedded files names restriction should be relaxed and/or documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions