Commit e8f49aa8 authored by Fazlul Shahriar's avatar Fazlul Shahriar Committed by Brad Fitzpatrick

cmd/go/internal/modload: ignore directories when looking for go.mod file in Plan 9

This fixes builds in Plan 9 under /n. Since directories in /n are
automatically created, /n/go.mod always exists.

Fixes #27074

Change-Id: Ie9a1155b7c316bdc27655f5b99172550b413838d
Reviewed-on: https://go-review.googlesource.com/129804Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1ba74448
......@@ -24,6 +24,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
)
......@@ -379,7 +380,7 @@ func FindModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string)
// Look for enclosing go.mod.
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !(runtime.GOOS == "plan9" && fi.IsDir()) {
return dir, "go.mod"
}
if dir == limit {
......@@ -397,7 +398,7 @@ func FindModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string)
dir = dir1
for {
for _, name := range altConfigs {
if _, err := os.Stat(filepath.Join(dir, name)); err == nil {
if fi, err := os.Stat(filepath.Join(dir, name)); err == nil && !(runtime.GOOS == "plan9" && fi.IsDir()) {
return dir, name
}
}
......
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package modload
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestFindModuleRootIgnoreDir(t *testing.T) {
// In Plan 9, directories are automatically created in /n.
// For example, /n/go.mod always exist, but it's a directory.
// Test that we ignore directories when trying to find go.mod and other config files.
dir, err := ioutil.TempDir("", "gotest")
if err != nil {
t.Fatalf("failed to create temporary directory: %v", err)
}
defer os.RemoveAll(dir)
if err := os.Mkdir(filepath.Join(dir, "go.mod"), os.ModeDir|0755); err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
for _, name := range altConfigs {
if err := os.MkdirAll(filepath.Join(dir, name), os.ModeDir|0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
}
p := filepath.Join(dir, "example")
if err := os.Mkdir(p, os.ModeDir|0755); err != nil {
t.Fatalf("Mkdir failed: %v", err)
}
if root, _ := FindModuleRoot(p, "", false); root != "" {
t.Errorf("FindModuleRoot(%q, \"\", false): %q, want empty string", p, root)
}
if root, _ := FindModuleRoot(p, "", true); root != "" {
t.Errorf("FindModuleRoot(%q, \"\", true): %q, want empty string", p, root)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment