This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Resolve symlinks if project root has them. #247
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
76cfb05
resolve symlinks if project root is within symlinked directory
brianstarke 6c8491c
small cleanup
brianstarke 0047ea1
Moved symlink evaluation to LoadProject function, split out symlink eval
brianstarke f41f58a
Merge branch 'master' into resolve-symlinks
5a56a59
use filepath join to use correct os.Separator in file path
brianstarke bbf9364
Merge branch 'resolve-symlinks' of github.com:brianstarke/dep into re…
brianstarke c922a91
check if real path is within GOPATH before resolving
brianstarke ab79f83
fixes from review, added lstat passthrough
brianstarke 4e3205d
check all GOPATHS
brianstarke f5c52ec
clearer error message
brianstarke 0628b80
remove extra quotation mark
brianstarke f569ebc
Forgot to commit test updates
brianstarke 382d489
Merge branch 'master' of github.com:brianstarke/dep into resolve-syml…
brianstarke c2deecc
use errors package instead of fmt
brianstarke 753c8dd
Add test case for multiple GOPATH situation
brianstarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,13 @@ func (c *Ctx) LoadProject(path string) (*Project, error) { | |
// | ||
// The second returned string indicates which GOPATH value was used. | ||
func (c *Ctx) SplitAbsoluteProjectRoot(path string) (string, error) { | ||
// the path may lie within a symlinked directory, resolve those first | ||
path, err := filepath.EvalSymlinks(path) | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("failed attempt to resolve symlinks: %s", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our patterns around error handling aren't exactly the best right now, but let's be consistent - when wrapping an error returned from a called function, please use |
||
} | ||
|
||
srcprefix := filepath.Join(c.GOPATH, "src") + string(filepath.Separator) | ||
if strings.HasPrefix(path, srcprefix) { | ||
// filepath.ToSlash because we're dealing with an import path now, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) { | |
defer h.Cleanup() | ||
|
||
h.TempDir("src") | ||
|
||
h.Setenv("GOPATH", h.Path(".")) | ||
depCtx := &Ctx{GOPATH: h.Path(".")} | ||
|
||
|
@@ -44,6 +45,9 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) { | |
} | ||
|
||
for _, want := range importPaths { | ||
// create the target directory so lstat doesn't fail | ||
h.TempDir(filepath.Join("src", want)) | ||
|
||
fullpath := filepath.Join(depCtx.GOPATH, "src", want) | ||
got, err := depCtx.SplitAbsoluteProjectRoot(fullpath) | ||
if err != nil { | ||
|
@@ -59,6 +63,24 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) { | |
if err == nil { | ||
t.Fatalf("should have gotten error but did not for tra/la/la/la: %s", got) | ||
} | ||
|
||
// test resolving project root is symlinked | ||
want := "real/full/path" | ||
symlinkedPath := filepath.Join(depCtx.GOPATH, "src", "sympath") | ||
|
||
h.TempDir(filepath.Join("src", want)) | ||
|
||
os.Symlink( | ||
filepath.Join(depCtx.GOPATH, "src", want), | ||
symlinkedPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just one line is fine, please |
||
|
||
got, err = depCtx.SplitAbsoluteProjectRoot(symlinkedPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if got != want { | ||
t.Fatalf("expected %s, got %s", want, got) | ||
} | ||
} | ||
|
||
func TestAbsoluteProjectRoot(t *testing.T) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling this within
SplitAbsoluteProjectRoot()
, let's do the symlink evaluation up inLoadProject()
. That keeps this a bit cleaner, by keeping this function solely dealing with symbolic strings, andLoadProject()
doing the actual filesystem work.