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

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

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

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

junhaideng opened this issue Sep 3, 2020 · 8 comments

Comments

@junhaideng
Copy link

junhaideng commented Sep 3, 2020

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

$ 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
Copy link
Contributor

Doesn’t you mean \host\share?

@junhaideng
Copy link
Author

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
Copy link
Member

mattn commented Sep 3, 2020

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

@networkimprov
Copy link

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

@junhaideng
Copy link
Author

\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 !
image

@junhaideng
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

junhaideng 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.

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 ❤️

@golang golang locked and limited conversation to collaborators Sep 3, 2021
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

6 participants