fixes from review, added lstat passthrough

This commit is contained in:
Brian Starke 2017-03-14 14:58:47 -04:00
Родитель c922a91d25
Коммит ab79f83fea
2 изменённых файлов: 16 добавлений и 10 удалений

Просмотреть файл

@ -135,20 +135,26 @@ func (c *Ctx) LoadProject(path string) (*Project, error) {
//
// If the passed path isn't a symlink at all, we just pass through.
func (c *Ctx) resolveProjectRoot(path string) (string, error) {
// Determine if this is a symlink
// Determine if this path is a Symlink
l, err := os.Lstat(path)
if err != nil {
return "", errors.Wrap(err, "resolveProjectRoot")
}
// Pass through if not
if l.Mode()&os.ModeSymlink == 0 {
return path, nil
}
// Resolve path
resolved, err := filepath.EvalSymlinks(path)
if err != nil {
return "", errors.Wrap(err, "resolveProjectRoot")
}
// Not a symlink, move on
if resolved == path {
return path, nil
}
// Determine if the symlink is within the GOPATH, in which case we're not
// sure how to resolve it.
if strings.HasPrefix(path, c.GOPATH) {
if filepath.HasPrefix(path, c.GOPATH) {
return "", fmt.Errorf("''%s' is linked to another path within GOPATH", path)
}

Просмотреть файл

@ -375,7 +375,7 @@ func TestResolveProjectRoot(t *testing.T) {
t.Fatalf("Error resolving project root: %s", err)
}
if p != realPath {
t.Fatalf("Expected path to be %s, got %s", realPath, p)
t.Fatalf("Want path to be %s, got %s", realPath, p)
}
// Real path should be returned, symlink is outside GOPATH
@ -384,10 +384,10 @@ func TestResolveProjectRoot(t *testing.T) {
t.Fatalf("Error resolving project root: %s", err)
}
if p != realPath {
t.Fatalf("Expected path to be %s, got %s", realPath, p)
t.Fatalf("Want path to be %s, got %s", realPath, p)
}
// Sylinked path is inside GOPATH, should return error
// Symlinked path is inside GOPATH, should return error
_, err = ctx.resolveProjectRoot(symlinkedInGoPath)
if err == nil {
t.Fatalf("Expected an error")