]> Cypherpunks repositories - gostls13.git/commit
cmd/go: fix relative-path normalization in go.work files
authorBryan C. Mills <bcmills@google.com>
Tue, 1 Feb 2022 16:25:13 +0000 (11:25 -0500)
committerBryan Mills <bcmills@google.com>
Tue, 1 Feb 2022 20:35:43 +0000 (20:35 +0000)
commit5522f8c8e6132fe36e4da74f6628a9d63f643d60
treeee5c1f1e6dc5aba2ab89ad0d75f41912e76f8877
parente22a14b7eb1e4a172d0c20d14a0d2433fdf20e5c
cmd/go: fix relative-path normalization in go.work files

We had been statting 'dir' instead of 'absDir', which statted the
wrong directory if 'dir' was made relative to the location of the
go.work file and that location was different from the current working
directory.

While we're here, I also noticed some other dir-vs.-absDir
discrepancies. The haveDirs map had assumed relative, slash-separated
filesystem paths, but absolute paths on Windows are not
slash-separated and we do retain those. Moreover, if users hand-edit
the go.work file they may introduce non-canonical paths.
I have changed the haveDirs logic to retain absolute paths in their
platform-specific forms, and to call DropUse with the original path
from the go.work file instead of the newly-resolved path.

Fixes #50931
Updates #48257

Change-Id: Ib0a46179aa20c99f045aac5c7c02dbb55da455c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/382240
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/go/internal/workcmd/use.go
src/cmd/go/testdata/script/work_use_dot.txt [new file with mode: 0644]