Merge remote-tracking branch 'aosp/upstream' am: e7bc78aa7b

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1553908

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I58c3604c7fd477418f30179663050767cfa4fb75
This commit is contained in:
Colin Cross 2021-01-21 00:58:23 +00:00 committed by Automerger Merge Worker
commit 3d9a6b397e
2 changed files with 23 additions and 17 deletions

View file

@ -538,10 +538,22 @@ func listDirsRecursiveRelative(fs FileSystem, name string, follow ShouldFollowSy
continue
}
f = filepath.Join(name, f)
if isSymlink, _ := fs.IsSymlink(f); isSymlink && follow == DontFollowSymlinks {
continue
var info os.FileInfo
if follow == DontFollowSymlinks {
info, err = fs.Lstat(f)
if err != nil {
continue
}
if info.Mode()&os.ModeSymlink != 0 {
continue
}
} else {
info, err = fs.Stat(f)
if err != nil {
continue
}
}
if isDir, _ := fs.IsDir(f); isDir {
if info.IsDir() {
dirs = append(dirs, f)
subDirs, err := listDirsRecursiveRelative(fs, f, follow, depth)
if err != nil {

View file

@ -76,24 +76,18 @@ func startGlob(fs FileSystem, pattern string, excludes []string,
}
for i, match := range matches {
isSymlink, err := fs.IsSymlink(match)
var info os.FileInfo
if follow == DontFollowSymlinks {
info, err = fs.Lstat(match)
} else {
info, err = fs.Stat(match)
}
if err != nil {
return nil, nil, err
}
if !(isSymlink && follow == DontFollowSymlinks) {
isDir, err := fs.IsDir(match)
if os.IsNotExist(err) {
if isSymlink {
return nil, nil, fmt.Errorf("%s: dangling symlink", match)
}
}
if err != nil {
return nil, nil, fmt.Errorf("%s: %s", match, err.Error())
}
if isDir {
matches[i] = match + "/"
}
if info.IsDir() {
matches[i] = match + "/"
}
}