Skip to content

Commit

Permalink
fixes from review, added lstat passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstarke committed Mar 14, 2017
1 parent c922a91 commit ab79f83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 11 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
resolved, err := filepath.EvalSymlinks(path)
// Determine if this path is a Symlink
l, err := os.Lstat(path)
if err != nil {
return "", errors.Wrap(err, "resolveProjectRoot")
}

// Not a symlink, move on
if resolved == path {
// 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")
}

// 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)
}

Expand Down
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit ab79f83

Please sign in to comment.