Normalize All The Path Cache Keys Summary: Equivalent paths do not always hash equally. When used as hash table keys, Paths need to be normalized and either absolute or relative to the same directory. This change normalizes the Paths used as hash keys in the DefaultFileHashCache to ensure the cache works as intended. Test Plan: 0) buckd 1) buck test --all 2) add a failing assertion to a test 3) buck test --all 4) ensure that step 3 fails
diff --git a/src/com/facebook/buck/util/DefaultFileHashCache.java b/src/com/facebook/buck/util/DefaultFileHashCache.java index f2d6509..7c0a98f 100644 --- a/src/com/facebook/buck/util/DefaultFileHashCache.java +++ b/src/com/facebook/buck/util/DefaultFileHashCache.java
@@ -71,7 +71,7 @@ public HashCode get(Path path) { HashCode sha1; try { - sha1 = loadingCache.get(path); + sha1 = loadingCache.get(path.normalize()); } catch (ExecutionException e) { throw new RuntimeException(e); } @@ -92,7 +92,7 @@ if (projectFilesystem.isPathChangeEvent(event)) { // Path event, remove the path from the cache as it has been changed, added or deleted. Path path = (Path) event.context(); - loadingCache.invalidate(path); + loadingCache.invalidate(path.normalize()); } else { // Non-path change event, likely an overflow due to many change events: invalidate everything. loadingCache.invalidateAll();