Commit a4d75f1d authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Fix recursive FilePathWatcher on Linux when touching a directory

FilePathWatcher is DCHECKing when touching a directory for a recursive
directory, this is due to invariant being broken between members:
|recursive_paths_by_watch_| and |recursive_watches_by_path_|. Function
UpdateRecursiveWatches() was erasing from |recursive_watches_by_path_|,
but wasn't erasing from |recursive_paths_by_watch_|.

This CL fixes UpdateRecursiveWatches() to maintain the invariant, by
erasing from |recursive_paths_by_watch_| too.

Test: base_unittests --gtest_filter="*RecursiveWatch*"
Bug: 995196
Change-Id: Ibcc8b015d7d9b68d2eff59f4ae9e87d84d76991f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757960Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688430}
parent 28c1326e
......@@ -629,6 +629,9 @@ void FilePathWatcherImpl::UpdateRecursiveWatches(
break;
if (!DirectoryExists(cur_path))
g_inotify_reader.Get().RemoveWatch(end_it->second, this);
// Keep it in sync with |recursive_watches_by_path_| crbug.com/995196.
recursive_paths_by_watch_.erase(end_it->second);
}
recursive_watches_by_path_.erase(start_it, end_it);
UpdateRecursiveWatchesForPath(changed_dir);
......
......@@ -501,6 +501,16 @@ TEST_F(FilePathWatcherTest, RecursiveWatch) {
ASSERT_TRUE(base::CreateDirectory(subdir));
ASSERT_TRUE(WaitForEvents());
// Mac and Win don't generate events for Touch.
// Android TouchFile returns false.
#if !(defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID))
// Touch "$dir".
Time access_time;
ASSERT_TRUE(Time::FromString("Wed, 16 Nov 1994, 00:00:00", &access_time));
ASSERT_TRUE(base::TouchFile(dir, access_time, access_time));
ASSERT_TRUE(WaitForEvents());
#endif // !(defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_ANDROID))
// Create "$dir/subdir/subdir_file1".
FilePath subdir_file1(subdir.AppendASCII("subdir_file1"));
ASSERT_TRUE(WriteFile(subdir_file1, "content"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment