Skip to content
Snippets Groups Projects
Commit 10ed134a authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Damien Neil
Browse files

os: improve Windows fixLongPath

CL 574695 added caching the os.Chdir argument for Windows, and used the
cached value to assess the length of the current working directory in
addExtendedPrefix (used by fixLongPath).

It did not take into account that Chdir can accept relative paths, and
thus the pathLength calculation in addExtendedPrefix can be wrong.

Let's only cache the os.Chdir argument if it's absolute, and clean the
cache otherwise, thus improving the correctness of fixLongPath.

For #41734
For #21782
For #36375

Change-Id: Ie24a5ed763a7aacc310666d2e4cbb8e298768670
Reviewed-on: https://go-review.googlesource.com/c/go/+/607437


Reviewed-by: default avatarIan Lance Taylor <iant@google.com>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
Reviewed-by: default avatarDamien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: default avatarQuim Muntal <quimmuntal@gmail.com>
Reviewed-by: default avatarCherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
parent d2879efd
No related branches found
No related tags found
No related merge requests found
......@@ -344,8 +344,13 @@ func Chdir(dir string) error {
return &PathError{Op: "chdir", Path: dir, Err: e}
}
if runtime.GOOS == "windows" {
abs := filepathlite.IsAbs(dir)
getwdCache.Lock()
getwdCache.dir = dir
if abs {
getwdCache.dir = dir
} else {
getwdCache.dir = ""
}
getwdCache.Unlock()
}
if log := testlog.Logger(); log != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment