Skip to content

Commit

Permalink
godoc: don't try to follow all symlinks
Browse files Browse the repository at this point in the history
Revert https://golang.org/cl/45096.

Original change description:
    godoc: follow symbolic links to folders in GOROOT

    Directory walking in godoc relies on ReadDir which returns the result
    of os.Lstat.

    Instead make the the OS VFS's ReadDir use os.Stat on symlinks before
    returning.

Updates golang/go#15049
Fixes golang/go#21061

Change-Id: Ieaa7923d85842f3da5696a7f46134d16407dae66
Reviewed-on: https://go-review.googlesource.com/53634
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
ianlancetaylor committed Aug 7, 2017
1 parent 0f5d61c commit f03b335
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 139 deletions.
32 changes: 2 additions & 30 deletions godoc/vfs/os.go
Expand Up @@ -7,11 +7,9 @@ package vfs
import (
"fmt"
"io/ioutil"
"log"
"os"
pathpkg "path"
"path/filepath"
"strings"
)

// OS returns an implementation of FileSystem reading from the
Expand Down Expand Up @@ -59,35 +57,9 @@ func (root osFS) Lstat(path string) (os.FileInfo, error) {
}

func (root osFS) Stat(path string) (os.FileInfo, error) {
return stat(root.resolve(path))
return os.Stat(root.resolve(path))
}

var readdir = ioutil.ReadDir // for testing
var stat = os.Stat // for testing

func (root osFS) ReadDir(path string) ([]os.FileInfo, error) {
fis, err := readdir(root.resolve(path))
if err != nil {
return fis, err
}
ret := fis[:0]

// reread the files with os.Stat since they might be symbolic links
for _, fi := range fis {
if fi.Mode()&os.ModeSymlink != 0 {
baseName := fi.Name()
fi, err = root.Stat(pathpkg.Join(path, baseName))
if err != nil {
if os.IsNotExist(err) && strings.HasPrefix(baseName, ".") {
// Ignore editor spam files without log spam.
continue
}
log.Printf("ignoring symlink: %v", err)
continue
}
}
ret = append(ret, fi)
}

return ret, nil // is sorted
return ioutil.ReadDir(root.resolve(path)) // is sorted
}
109 changes: 0 additions & 109 deletions godoc/vfs/os_test.go

This file was deleted.

0 comments on commit f03b335

Please sign in to comment.