Clearer error in case of Android.bp being unreadable
Bug: 64600838 Test: mkdir errtest \ && ln -s /tmp/dontexist errtest/Android.bp \ # and add errtest to ./Android.bp \ && m nothing \ # and check that the error message mentions a symlink Change-Id: I841ec12d613f61ccc3396538062bee48c8c1ca27
This commit is contained in:
parent
18a0d2e9b5
commit
aca4220583
2 changed files with 28 additions and 0 deletions
18
context.go
18
context.go
|
@ -19,6 +19,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
|
@ -793,6 +794,23 @@ func (c *Context) parseBlueprintsFile(filename string, scope *parser.Scope, root
|
|||
|
||||
f, err := c.fs.Open(filename)
|
||||
if err != nil {
|
||||
// couldn't open the file; see if we can provide a clearer error than "could not open file"
|
||||
stats, statErr := c.fs.Lstat(filename)
|
||||
if statErr == nil {
|
||||
isSymlink := stats.Mode()&os.ModeSymlink != 0
|
||||
if isSymlink {
|
||||
err = fmt.Errorf("could not open symlink %v : %v", filename, err)
|
||||
target, readlinkErr := os.Readlink(filename)
|
||||
if readlinkErr == nil {
|
||||
_, targetStatsErr := c.fs.Lstat(target)
|
||||
if targetStatsErr != nil {
|
||||
err = fmt.Errorf("could not open symlink %v; its target (%v) cannot be opened", filename, target)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("%v exists but could not be opened: %v", filename, err)
|
||||
}
|
||||
}
|
||||
errsCh <- []error{err}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package pathtools
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -61,6 +62,7 @@ type FileSystem interface {
|
|||
Glob(pattern string, excludes []string) (matches, dirs []string, err error)
|
||||
glob(pattern string) (matches []string, err error)
|
||||
IsDir(name string) (bool, error)
|
||||
Lstat(name string) (os.FileInfo, error)
|
||||
}
|
||||
|
||||
// osFs implements FileSystem using the local disk.
|
||||
|
@ -94,6 +96,10 @@ func (osFs) glob(pattern string) ([]string, error) {
|
|||
return filepath.Glob(pattern)
|
||||
}
|
||||
|
||||
func (osFs) Lstat(path string) (stats os.FileInfo, err error) {
|
||||
return os.Lstat(path)
|
||||
}
|
||||
|
||||
type mockFs struct {
|
||||
files map[string][]byte
|
||||
dirs map[string]bool
|
||||
|
@ -150,3 +156,7 @@ func (m *mockFs) glob(pattern string) ([]string, error) {
|
|||
}
|
||||
return matches, nil
|
||||
}
|
||||
|
||||
func (m *mockFs) Lstat(path string) (stats os.FileInfo, err error) {
|
||||
return nil, errors.New("Lstat is not yet implemented in MockFs")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue