Skip to content

Commit 10ed134

Browse files
kolyshkinneild
authored andcommitted
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 golang#41734 For golang#21782 For golang#36375 Change-Id: Ie24a5ed763a7aacc310666d2e4cbb8e298768670 Reviewed-on: https://go-review.googlesource.com/c/go/+/607437 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Alex Brainman <[email protected]> Reviewed-by: Damien Neil <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Quim Muntal <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent d2879ef commit 10ed134

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/os/file.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,13 @@ func Chdir(dir string) error {
344344
return &PathError{Op: "chdir", Path: dir, Err: e}
345345
}
346346
if runtime.GOOS == "windows" {
347+
abs := filepathlite.IsAbs(dir)
347348
getwdCache.Lock()
348-
getwdCache.dir = dir
349+
if abs {
350+
getwdCache.dir = dir
351+
} else {
352+
getwdCache.dir = ""
353+
}
349354
getwdCache.Unlock()
350355
}
351356
if log := testlog.Logger(); log != nil {

0 commit comments

Comments
 (0)