Skip to content

cmd/go: go.mod go get does not keep file mode (it breaks symbolic links in package) #28312

Closed
@karupanerura

Description

@karupanerura

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

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/karupanerura/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/karupanerura/.go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/karupanerura/project/myapp/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/5cs_2lx107bb7thp7qrhw68spwnl58/T/go-build478980627=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I started to use go mod. And import this package: https://github.com/kentaro/go-hoedown
But go get creates broken package files on $GOPATH/mod/github.com/kentaro/[email protected].
Because this repository uses symbolic links to import external package's c files and compile it with cgo, but cmd/go/internal/modfetch/unzip ignores file mode.

What did you expect to see?

I think keep file type using zip file (extra) header. I tried following patch:

diff --git a/src/cmd/go/internal/modfetch/unzip.go b/src/cmd/go/internal/modfetch/unzip.go
index a50431fd86..765b68d9f5 100644
--- a/src/cmd/go/internal/modfetch/unzip.go
+++ b/src/cmd/go/internal/modfetch/unzip.go
@@ -113,7 +113,7 @@ func Unzip(dir, zipfile, prefix string, maxSize int64) error {
                if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
                        return err
                }
-               w, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0444)
+               w, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, zf.Mode()&7444) // keep file type and makes read only file
                if err != nil {
                        return fmt.Errorf("unzip %v: %v", zipfile, err)
                }

But, it's not works. (maybe, is it archive/zip's bug?)

What did you see instead?

nop 😢

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions