Skip to content

Commit 166fff7

Browse files
authored
interp: add safeguards when searching for vendor root.
With certain yaegi configuration on Windows, the loop in `previousRoot` can be infinite, because it fails to recognize driver letters as root. This change adds a few more safeguards: checks path prefix earlier and checks if `filepath.Dir` produces an empty path.
1 parent 8efc4f0 commit 166fff7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

interp/src.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ func previousRoot(filesystem fs.FS, rootPath, root string) (string, error) {
248248
if !os.IsNotExist(err) {
249249
return "", err
250250
}
251+
// stop when we reach GOPATH/src
252+
if parent == prefix {
253+
break
254+
}
251255

252256
// stop when we reach GOPATH/src/blah
253257
parent = filepath.Dir(parent)
@@ -259,7 +263,8 @@ func previousRoot(filesystem fs.FS, rootPath, root string) (string, error) {
259263
// we are dealing with relative paths).
260264
// TODO(mpl): It should probably be a critical error actually,
261265
// as we shouldn't have gone that high up in the tree.
262-
if parent == string(filepath.Separator) || parent == "." {
266+
// TODO(dennwc): This partially fails on Windows, since it cannot recognize drive letters as "root".
267+
if parent == string(filepath.Separator) || parent == "." || parent == "" {
263268
break
264269
}
265270
}

0 commit comments

Comments
 (0)