From 648a21ab5c310860f9dcf8415aa4f105c5bf982a Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Tue, 4 Jan 2022 16:11:45 -0800 Subject: [PATCH] [Linux] Correct handling of new dirs added to non-recursive watch roots Signed-off-by: Chris Burel --- .../native/FileWatcher/FileWatcher_linux.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp b/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp index 7d38372e18..4ca41c0cb9 100644 --- a/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp +++ b/Code/Tools/AssetProcessor/Platform/Linux/native/FileWatcher/FileWatcher_linux.cpp @@ -176,10 +176,25 @@ void FileWatcher::WatchFolderLoop() if (event->mask & (IN_CREATE | IN_MOVED_TO)) { - if (event->mask & IN_ISDIR /*&& m_recursive*/) + if (event->mask & IN_ISDIR) { - // New Directory, add it to the watch - m_platformImpl->AddWatchFolder(pathStr, true); + // New Directory, see if it should be added to the watched directories + // It is only added if it is a child of a recursively watched directory + const auto found = AZStd::find_if(begin(m_folderWatchRoots), end(m_folderWatchRoots), [this, event](const WatchRoot& watchRoot) + { + return watchRoot.m_directory == m_platformImpl->m_handleToFolderMap[event->wd]; + }); + + // If the path is not in m_folderWatchRoots, it must + // be a new subdirectory of a subdirectory of some + // other root that is being watched recursively. + // Maintain the recursive nature of that root. + const bool shouldAddFolder = (found == end(m_folderWatchRoots)) ? true : found->m_recursive; + + if (shouldAddFolder) + { + m_platformImpl->AddWatchFolder(pathStr, true); + } } else {