@@ -73,6 +73,9 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
73
73
74
74
err = filepath .Walk (fileRoot , func (wp string , fi os.FileInfo , err error ) error {
75
75
if err != nil && err != filepath .SkipDir {
76
+ if os .IsPermission (err ) {
77
+ return filepath .SkipDir
78
+ }
76
79
return err
77
80
}
78
81
if ! fi .IsDir () {
@@ -97,25 +100,29 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
97
100
return filepath .SkipDir
98
101
}
99
102
100
- // The entry error is nil when visiting a directory that itself is
101
- // untraversable, as it's still governed by the parent directory's
102
- // perms. We have to check readability of the dir here, because
103
- // otherwise we'll have an empty package entry when we fail to read any
104
- // of the dir's contents.
105
- //
106
- // If we didn't check here, then the next time this closure is called it
107
- // would have an err with the same path as is called this time, as only
108
- // then will filepath.Walk have attempted to descend into the directory
109
- // and encountered an error.
110
- var f * os.File
111
- f , err = os .Open (wp )
112
- if err != nil {
113
- if os .IsPermission (err ) {
114
- return filepath .SkipDir
103
+ {
104
+ // For Go 1.9 and earlier:
105
+ //
106
+ // The entry error is nil when visiting a directory that itself is
107
+ // untraversable, as it's still governed by the parent directory's
108
+ // perms. We have to check readability of the dir here, because
109
+ // otherwise we'll have an empty package entry when we fail to read any
110
+ // of the dir's contents.
111
+ //
112
+ // If we didn't check here, then the next time this closure is called it
113
+ // would have an err with the same path as is called this time, as only
114
+ // then will filepath.Walk have attempted to descend into the directory
115
+ // and encountered an error.
116
+ var f * os.File
117
+ f , err = os .Open (wp )
118
+ if err != nil {
119
+ if os .IsPermission (err ) {
120
+ return filepath .SkipDir
121
+ }
122
+ return err
115
123
}
116
- return err
124
+ f . Close ()
117
125
}
118
- f .Close ()
119
126
120
127
// Compute the import path. Run the result through ToSlash(), so that
121
128
// windows file paths are normalized to slashes, as is expected of
0 commit comments