Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Allow to run dep ensure in working directories which are symlinks #741

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (c *Ctx) SetPaths(workingDir string, gopaths ...string) error {
for _, gp := range gopaths {
gp = filepath.FromSlash(gp)

if fs.HasFilepathPrefix(wd, gp) {
ok, err := hasFilepathPrefix(wd, gp)
if err != nil {
return errors.Wrap(err, "failed to check the path")
}
if ok {
c.GOPATH = gp
}

Expand Down Expand Up @@ -114,6 +118,19 @@ func defaultGOPATH() string {
return ""
}

// Similar to fs.HasFilepathPrefix() but aware of symlinks.
func hasFilepathPrefix(path, prefix string) (bool, error) {
p, err := filepath.EvalSymlinks(path)
if err != nil {
return false, errors.Wrap(err, "failed to resolve the symlink")
}
pre, err := filepath.EvalSymlinks(prefix)
if err != nil {
return false, errors.Wrap(err, "failed to resolve the symlink")
}
return fs.HasFilepathPrefix(p, pre), nil
}

func (c *Ctx) SourceManager() (*gps.SourceMgr, error) {
return gps.NewSourceManager(filepath.Join(c.GOPATH, "pkg", "dep"))
}
Expand Down