Skip to content

path/filepath: Join doesn't add the required \ after volume name in Windows #46990

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

Closed
shrinidhi111 opened this issue Jun 30, 2021 · 5 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@shrinidhi111
Copy link

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

$ go version 
go1.16.5 windows/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
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\USER\AppData\Local\go-build
set GOENV=C:\Users\USER\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\USER\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\USER\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\USER\source\repos\😶\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\USER\AppData\Local\Temp\go-build132155260=/tmp/go-build -gno-record-gcc-switches

What did you do?

	var ProgramData string = "ProgramData"
	var FolderOfInterest string = "MyHiddenFolder"
	var getsomedir, _ = os.UserHomeDir()
	var PathToMyFolder string = filepath.Join(filepath.VolumeName(getsomedir), ProgramData, FolderOfInterest)
	
	fmt.Println(PathToMyFolder)

What did you expect to see?

C:\ProgramData\MyHiddenFolder

What did you see instead?

C:ProgramData\MyHiddenFolder

Description

I am writing a cross-platform app and on Windows, I store some data in the ProgramData folder. It turns out there is no rule that C: drive should be the root all the time... So to make the application get root volume dynamically,

  1. I get some path from env
  2. Extract Volume info
  3. Use filepath.Join to construct my complete path.

Issue

filepath.Join is missing \ after C:. That's literally its only purpose

@dmitshur dmitshur changed the title FilePath is not adding the required \ in Windows path/filepath: Join doesn't add the required \ after volume name in Windows Jun 30, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 30, 2021
@dmitshur dmitshur added this to the Backlog milestone Jun 30, 2021
@seankhliao
Copy link
Member

previously #26953

@ianlancetaylor
Copy link
Member

See #11551 and #26953. I don't think we can change this now. Sorry.

@shrinidhi111
Copy link
Author

I went through the tickets but I don't get them. From the picture below clearly it is not the correct format.

image

But other places in Go actually prints the whole path including \ after :. Like filepath.Abs()

@shrinidhi111
Copy link
Author

As of now I've added this to fix in my code ::

var PathToMyFolder string = filepath.Join(filepath.VolumeName(getsomedir), "\\", ProgramData, FolderOfInterest)

@ianlancetaylor
Copy link
Member

On Windows C:ProgramData is a meaningful path. C:\ProgramData is also a meaningful path. They mean different things. The first one means something like "the subdirectory named ProgramData in the current directory on drive C". The second one means something like "the subdirectory named ProgramData in the root directory on drive C". See, e.g., https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats.

@golang golang locked and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants