Skip to content

Commit

Permalink
Revert "Merge pull request golang#157 from ReSTARTR/read-symlink"
Browse files Browse the repository at this point in the history
This reverts commit 67b7104, reversing
changes made to db8fd63.
  • Loading branch information
sdboyer committed Mar 6, 2017
1 parent 67b7104 commit b87665c
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 121 deletions.
1 change: 0 additions & 1 deletion _testdata/src/gosimple

This file was deleted.

1 change: 0 additions & 1 deletion _testdata/src/symlinks/broken

This file was deleted.

1 change: 0 additions & 1 deletion _testdata/src/symlinks/foo/bar

This file was deleted.

7 changes: 0 additions & 7 deletions _testdata/src/symlinks/foo/foo.go

This file was deleted.

1 change: 0 additions & 1 deletion _testdata/src/symlinks/foobar

This file was deleted.

1 change: 0 additions & 1 deletion _testdata/src/symlinks/gopkg

This file was deleted.

1 change: 0 additions & 1 deletion _testdata/src/symlinks/pkg/bar

This file was deleted.

5 changes: 0 additions & 5 deletions _testdata/src/symlinks/pkg/gopkg.go

This file was deleted.

12 changes: 0 additions & 12 deletions _testdata/src/symlinks/symlinks.go

This file was deleted.

32 changes: 1 addition & 31 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
if err != nil && err != filepath.SkipDir {
return err
}

// Read the destination of named symbolic link
if fi, err := readSymlink(wp, fileRoot, fi); err != nil {
return nil
} else if !fi.IsDir() {
if !fi.IsDir() {
return nil
}

Expand Down Expand Up @@ -199,32 +195,6 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
return ptree, nil
}

func readSymlink(wp, fileRoot string, fi os.FileInfo) (os.FileInfo, error) {
// read only symlink dir
if fi.IsDir() || fi.Mode()&os.ModeSymlink == 0 {
return fi, nil
}

dst, err := os.Readlink(wp)
if err != nil {
return fi, err
}

// All absolute symlinks are disqualified; if one is encountered, it should be skipped.
if filepath.IsAbs(dst) {
return fi, nil
}

// Relative symlinks pointing to somewhere outside of the root (via ..) should also be skipped.
dst, err = filepath.EvalSymlinks(wp)
if err != nil {
return fi, nil
} else if !strings.HasPrefix(dst, fileRoot) {
return fi, nil
}
return os.Lstat(dst)
}

// fillPackage full of info. Assumes p.Dir is set at a minimum
func fillPackage(p *build.Package) error {
var buildPrefix = "// +build "
Expand Down
61 changes: 2 additions & 59 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,12 @@ func TestListPackages(t *testing.T) {
return filepath.Join(srcdir, filepath.Join(s...))
}

type tc struct {
table := map[string]struct {
fileRoot string
importRoot string
out PackageTree
err error
}
table := map[string]tc{
}{
"empty": {
fileRoot: j("empty"),
importRoot: "empty",
Expand Down Expand Up @@ -1235,62 +1234,6 @@ func TestListPackages(t *testing.T) {
},
},
}
if runtime.GOOS != "windows" {
table["follow_symlink"] = tc{
fileRoot: j("gosimple"),
importRoot: "gosimple",
out: PackageTree{
ImportRoot: "gosimple",
Packages: map[string]PackageOrErr{},
},
}
table["follow symlinks inside of package"] = tc{
fileRoot: j("symlinks"),
importRoot: "symlinks",
out: PackageTree{
ImportRoot: "symlinks",
Packages: map[string]PackageOrErr{
"symlinks/gopkg": {
P: Package{
ImportPath: "symlinks/gopkg",
CommentPath: "",
Name: "gopkg",
Imports: []string{},
},
},
"symlinks/pkg": {
P: Package{
ImportPath: "symlinks/pkg",
CommentPath: "",
Name: "gopkg",
Imports: []string{},
},
},
"symlinks": {
P: Package{
ImportPath: "symlinks",
CommentPath: "",
Name: "symlinks",
Imports: []string{
"github.com/sdboyer/gps",
"symlinks/gopkg",
},
},
},
"symlinks/foo": {
P: Package{
ImportPath: "symlinks/foo",
CommentPath: "",
Name: "foo",
Imports: []string{
"github.com/sdboyer/gps",
},
},
},
},
},
}
}

for name, fix := range table {
if _, err := os.Stat(fix.fileRoot); err != nil {
Expand Down
1 change: 0 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies:
- wget https://github.com/Masterminds/glide/releases/download/0.10.1/glide-0.10.1-linux-amd64.tar.gz
- tar -vxz -C $HOME/bin --strip=1 -f glide-0.10.1-linux-amd64.tar.gz
override:
- mkdir -p $HOME/.go_workspace/src
- glide --home $HOME/.glide -y glide.yaml install --cache
- mkdir -p $RD
- rsync -azC --delete ./ $RD
Expand Down

0 comments on commit b87665c

Please sign in to comment.