Fix hanging of finder_test

Previously there could be an infinite loop in the Finder's db export when
running tests on a system with few cores.

The Finder divides the cache-serialization work amongst cores. On systems with
enough cores, each path in TestFileSystemRoot would get its own core and the
infinite loop in the prefix calculation logic would be avoided. On systems with
fewer cores, the computation of the maximum common path could run forever.

This shouldn't have affected the general usage of the Finder in builds other
than in its unit tests, because the builds don't ask to include the
filesystem root as a path to scan. This should only have affected
finder_test.go which tested the filesystem root anyway.

Bug: 62455338
Test: m -j # which runs unit tests
Change-Id: I7a1467fb32e4538fb96833791180bfbfad5a3911
This commit is contained in:
Jeff Gaston 2017-08-22 13:33:19 -07:00
parent b3f1c8f5f5
commit 996716a8e2

View file

@ -661,6 +661,9 @@ func (f *Finder) serializeCacheEntry(dirInfos []dirFullInfo) ([]byte, error) {
for _, info := range infos {
for !strings.HasPrefix(info.P+"/", prefix+"/") {
prefix = filepath.Dir(prefix)
if prefix == "/" {
break
}
}
}
// remove common prefix