{{ message }}

# Unix/linux system filepath.VolumeName(\host\share\foo) return "" #41201

Closed
opened this issue Sep 3, 2020 · 8 comments
Closed

# Unix/linux system filepath.VolumeName(\host\share\foo) return ""#41201

opened this issue Sep 3, 2020 · 8 comments

$go version go version go1.14.7 linux/amd64  ### Does this issue reproduce with the latest release? Yes ### What operating system and processor architecture are you using (go env)? go env Output $ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/linux/.cache/go-build"
GOENV="/home/linux/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/linux/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
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-build771253865=/tmp/go-build -gno-record-gcc-switches"


### What did you do?

I ran the following code

fmt.Println(filepath.VolumeName(\host\share\foo))

### What did you expect to see?

the result should be \host\share like the doc says

### What did you see instead?

the result is ""

I have seen the source code, such as
path.go

// VolumeName returns leading volume name.
// Given "C:\foo\bar" it returns "C:" on Windows.
// Given "\\host\share\foo" it returns "\\host\share".
// On other platforms it returns "".
func VolumeName(path string) string {
return path[:volumeNameLen(path)]
}

path_unix.go

// volumeNameLen returns length of the leading volume name on Windows.
// It returns 0 elsewhere.
func volumeNameLen(path string) int {
return 0
}

so, in unix/linux system, volumeNameLen should be 0, and then VolumeName should be "", so is the doc wrong, or I got it wrong?
Thanks for solving my question

### davecheney commented Sep 3, 2020

 Doesn’t you mean \host\share?

### junhaideng commented Sep 3, 2020

 Doesn’t you mean \host\share? I am so sorry that I can not understand your words, I just can not get the right output of fmt.Println(filepath.VolumeName(\host\share\foo))  as the doc says

### mattn commented Sep 3, 2020

 \host\share\foo is not an UNC paths. It should be \\host\share\foo.

### networkimprov commented Sep 3, 2020

 Are you running the code on Linux or Windows? It's only effective on Windows.

### junhaideng commented Sep 3, 2020

 \host\share\foo is not an UNC paths. It should be \\host\share\foo. I have tried the following ones, but all of them are "" Can you give me the right code, thanks a lot !

### junhaideng commented Sep 3, 2020

 Are you running the code on Linux or Windows? It's only effective on Windows. Yep, I ran it on the Linux machine with VMware WorksStation

### rsc commented Sep 3, 2020

 On non-Windows systems, VolumeName always returns "". The docs you quoted say: // On other platforms it returns "".  That seems to be the behavior you are observing.

### junhaideng commented Sep 3, 2020 • edited

 On non-Windows systems, VolumeName always returns "". The docs you quoted say: // On other platforms it returns "".  That seems to be the behavior you are observing. Oh, I got it wrong by others doc, thinking that \host\share\foo is a path on unix 😢 , thank all of you for your help ❤️
closed this Sep 3, 2020
mentioned this issue Sep 3, 2020