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

Commit

Permalink
Merge pull request #1221 from jmank88/pkgtree-ls-pkg
Browse files Browse the repository at this point in the history
pkgtree: add os.IsPermission check for walkFn err arg
  • Loading branch information
sdboyer committed Sep 26, 2017
2 parents 914a0bf + c1da7b8 commit 0979f44
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions internal/gps/pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {

err = filepath.Walk(fileRoot, func(wp string, fi os.FileInfo, err error) error {
if err != nil && err != filepath.SkipDir {
if os.IsPermission(err) {
return filepath.SkipDir
}
return err
}
if !fi.IsDir() {
Expand All @@ -97,25 +100,29 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
return filepath.SkipDir
}

// The entry error is nil when visiting a directory that itself is
// untraversable, as it's still governed by the parent directory's
// perms. We have to check readability of the dir here, because
// otherwise we'll have an empty package entry when we fail to read any
// of the dir's contents.
//
// If we didn't check here, then the next time this closure is called it
// would have an err with the same path as is called this time, as only
// then will filepath.Walk have attempted to descend into the directory
// and encountered an error.
var f *os.File
f, err = os.Open(wp)
if err != nil {
if os.IsPermission(err) {
return filepath.SkipDir
{
// For Go 1.9 and earlier:
//
// The entry error is nil when visiting a directory that itself is
// untraversable, as it's still governed by the parent directory's
// perms. We have to check readability of the dir here, because
// otherwise we'll have an empty package entry when we fail to read any
// of the dir's contents.
//
// If we didn't check here, then the next time this closure is called it
// would have an err with the same path as is called this time, as only
// then will filepath.Walk have attempted to descend into the directory
// and encountered an error.
var f *os.File
f, err = os.Open(wp)
if err != nil {
if os.IsPermission(err) {
return filepath.SkipDir
}
return err
}
return err
f.Close()
}
f.Close()

// Compute the import path. Run the result through ToSlash(), so that
// windows file paths are normalized to slashes, as is expected of
Expand Down

0 comments on commit 0979f44

Please sign in to comment.