Skip to content

Commit

Permalink
Invalidate parent directories (#5000)
Browse files Browse the repository at this point in the history
### Problem

Watchman `4.9.0` does not send events for a parent when a child is created or deleted, which causes issues like #4662.

### Solution

Revert to explicitly invalidating the parent directory when a child has changed. More precision is possible here, but it's possible that re-gaining the precision by using the `notify` crate would be preferable (see #4999).

### Result

Fixes #4662.
  • Loading branch information
Stu Hood authored Oct 19, 2017
1 parent 3bd433a commit 0c15fc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/python/pants/engine/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,12 @@ def root_entries(self, execution_request):
self._execution_request, execution_request))
return self._scheduler.root_entries(execution_request)

def invalidate_files(self, filenames):
def invalidate_files(self, direct_filenames):
"""Calls `Graph.invalidate_files()` against an internal product Graph instance."""
# NB: Watchman will never trigger an invalidation event for the root directory that
# is being watched. Instead, we treat any invalidation of a path directly in the
# root directory as an invalidation of the root.
if any(os.path.dirname(f) in ('', '.') for f in filenames):
filenames = tuple(filenames) + ('', '.')
# NB: Watchman no longer triggers events when children are created/deleted under a directory,
# so we always need to invalidate the direct parent as well.
filenames = set(direct_filenames)
filenames.update(os.path.dirname(f) for f in direct_filenames)
with self._product_graph_lock:
invalidated = self._scheduler.invalidate(filenames)
logger.debug('invalidated %d nodes for: %s', invalidated, filenames)
Expand Down
5 changes: 1 addition & 4 deletions tests/python/pants_test/engine/legacy/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ def test_invalidate_fsnode_incremental(self):

# Invalidate the '3rdparty/python' DirectoryListing, the `3rdparty` DirectoryListing,
# and then the root DirectoryListing by "touching" files/dirs.
# NB: Invalidation of entries in the root directory is special: because Watchman will
# never trigger an event for the root itself, we treat changes to files in the root
# directory as events for the root.
for filename in ('3rdparty/python/BUILD', '3rdparty/python', 'non_existing_file'):
for filename in ('3rdparty/python/BUILD', '3rdparty/jvm', 'non_existing_file'):
invalidated_count = scheduler.invalidate_files([filename])
self.assertGreater(invalidated_count,
0,
Expand Down

0 comments on commit 0c15fc9

Please sign in to comment.