Skip to content

Commit f03b335

Browse files
godoc: don't try to follow all symlinks
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 0f5d61c commit f03b335

File tree

2 files changed

+2
-139
lines changed

2 files changed

+2
-139
lines changed

godoc/vfs/os.go

+2-30
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ package vfs
77
import (
88
"fmt"
99
"io/ioutil"
10-
"log"
1110
"os"
1211
pathpkg "path"
1312
"path/filepath"
14-
"strings"
1513
)
1614

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

6159
func (root osFS) Stat(path string) (os.FileInfo, error) {
62-
return stat(root.resolve(path))
60+
return os.Stat(root.resolve(path))
6361
}
6462

65-
var readdir = ioutil.ReadDir // for testing
66-
var stat = os.Stat // for testing
67-
6863
func (root osFS) ReadDir(path string) ([]os.FileInfo, error) {
69-
fis, err := readdir(root.resolve(path))
70-
if err != nil {
71-
return fis, err
72-
}
73-
ret := fis[:0]
74-
75-
// reread the files with os.Stat since they might be symbolic links
76-
for _, fi := range fis {
77-
if fi.Mode()&os.ModeSymlink != 0 {
78-
baseName := fi.Name()
79-
fi, err = root.Stat(pathpkg.Join(path, baseName))
80-
if err != nil {
81-
if os.IsNotExist(err) && strings.HasPrefix(baseName, ".") {
82-
// Ignore editor spam files without log spam.
83-
continue
84-
}
85-
log.Printf("ignoring symlink: %v", err)
86-
continue
87-
}
88-
}
89-
ret = append(ret, fi)
90-
}
91-
92-
return ret, nil // is sorted
64+
return ioutil.ReadDir(root.resolve(path)) // is sorted
9365
}

godoc/vfs/os_test.go

-109
This file was deleted.

0 commit comments

Comments
 (0)