Fix finder on symlinks pointing to directories
When finder encountered a symlink pointing to a directory it attempted to ignore it, but becuase Lstat returns the a *os.FileInfo for the symlink the child.IsDir() check always returned false. Call Stat on the symlink to get the *os.FileInfo for the target of the symlink. Bug: 157656545 Test: finder_test.go Change-Id: Ie33d2e05d5c435b48e83eaeadf7b3c9816398404
This commit is contained in:
@@ -1393,17 +1393,25 @@ func (f *Finder) listDirSync(dir *pathMap) {
|
|||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
linkBits := child.Mode() & os.ModeSymlink
|
linkBits := child.Mode() & os.ModeSymlink
|
||||||
isLink := linkBits != 0
|
isLink := linkBits != 0
|
||||||
if child.IsDir() {
|
if isLink {
|
||||||
if !isLink {
|
childPath := filepath.Join(path, child.Name())
|
||||||
|
childStat, err := f.filesystem.Stat(childPath)
|
||||||
|
if err != nil {
|
||||||
|
// If stat fails this is probably a broken or dangling symlink, treat it as a file.
|
||||||
|
subfiles = append(subfiles, child.Name())
|
||||||
|
} else if childStat.IsDir() {
|
||||||
// Skip symlink dirs.
|
// Skip symlink dirs.
|
||||||
// We don't have to support symlink dirs because
|
// We don't have to support symlink dirs because
|
||||||
// that would cause duplicates.
|
// that would cause duplicates.
|
||||||
subdirs = append(subdirs, child.Name())
|
} else {
|
||||||
|
// We do have to support symlink files because the link name might be
|
||||||
|
// different than the target name
|
||||||
|
// (for example, Android.bp -> build/soong/root.bp)
|
||||||
|
subfiles = append(subfiles, child.Name())
|
||||||
}
|
}
|
||||||
|
} else if child.IsDir() {
|
||||||
|
subdirs = append(subdirs, child.Name())
|
||||||
} else {
|
} else {
|
||||||
// We do have to support symlink files because the link name might be
|
|
||||||
// different than the target name
|
|
||||||
// (for example, Android.bp -> build/soong/root.bp)
|
|
||||||
subfiles = append(subfiles, child.Name())
|
subfiles = append(subfiles, child.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1308,6 +1308,7 @@ func TestSymlinkPointingToDirectory(t *testing.T) {
|
|||||||
|
|
||||||
fs.Link(t, "/tmp/links/dir", "../dir", filesystem)
|
fs.Link(t, "/tmp/links/dir", "../dir", filesystem)
|
||||||
fs.Link(t, "/tmp/links/link", "../dir", filesystem)
|
fs.Link(t, "/tmp/links/link", "../dir", filesystem)
|
||||||
|
fs.Link(t, "/tmp/links/hi.txt", "../dir", filesystem)
|
||||||
fs.Link(t, "/tmp/links/broken", "nothingHere", filesystem)
|
fs.Link(t, "/tmp/links/broken", "nothingHere", filesystem)
|
||||||
fs.Link(t, "/tmp/links/recursive", "recursive", filesystem)
|
fs.Link(t, "/tmp/links/recursive", "recursive", filesystem)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user