Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
reddec opened this issue May 17, 2021 · 1 comment

Comments

@reddec
Copy link

reddec commented May 17, 2021

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.

@reddec reddec changed the title embed: Files starting with [ (squared brackets) or with : (double dots) are not embedded (undocumented behavior) embed: Files starting with : (double dots) are not embedded (undocumented behavior) May 17, 2021
@jayconrod
Copy link
Contributor

Duplicate of #44486.

We do need to fix this though: documentation of the restrictions should be more prominent, and the diagnostics should be clearer.

@golang golang locked and limited conversation to collaborators May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants