Skip to content

os: SameFile should not follow symlinks on windows #21854

@hirochachacha

Description

@hirochachacha

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

import (
	"fmt"
	"os"
)

func main() {
	f, err := os.Create("target")
	if err != nil {
		panic(err)
	}
	err = f.Close()
	if err != nil {
		panic(err)
	}
	defer os.Remove("target")
	err = os.Symlink("target", "symlink")
	if err != nil {
		panic(err)
	}
	defer os.Remove("symlink")
	st1, err := os.Lstat("symlink")
	if err != nil {
		panic(err)
	}
	st2, err := os.Lstat("target")
	if err != nil {
		panic(err)
	}
	fmt.Println(os.SameFile(st1, st2))
}

What did you expect to see?

false

What did you see instead?

true

Does this issue reproduce with the latest release (go1.9)?

I think so.

System details

go version go1.8 windows/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=".exe"
GOHOSTARCH="amd64"
GOHOSTOS="windows"
GOOS="windows"
GOPATH="C:\Users\Hiroshi\gopath"
GORACE=""
GOROOT="C:\Go"
GOTOOLDIR="C:\Go\pkg\tool\windows_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Hiroshi\AppData\Local\Temp\go-build553453167=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version go1.8 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.8 X:framepointer
gdb --version: GNU gdb (GDB) 7.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions