From abc462999e42e2f457504c6983a14cece4826246 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 23 Aug 2024 10:04:17 -0400 Subject: [PATCH] LibCore: Remove monitored file data before invoking system calls The monitored files can be internally removed by inotify. If we then try to explicitly remove them, the inotify_rm_watch call will fail. We do this when the file is deleted and we receive an IN_DELETE event. This ensures we clean up the monitored files. --- Userland/Libraries/LibCore/FileWatcherLinux.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibCore/FileWatcherLinux.cpp b/Userland/Libraries/LibCore/FileWatcherLinux.cpp index 0aaade3d56e..d0dd7808e6b 100644 --- a/Userland/Libraries/LibCore/FileWatcherLinux.cpp +++ b/Userland/Libraries/LibCore/FileWatcherLinux.cpp @@ -164,12 +164,12 @@ ErrorOr FileWatcherBase::remove_watch(ByteString path) return false; } - if (::inotify_rm_watch(m_watcher_fd, it->value) < 0) - return Error::from_errno(errno); - m_path_to_wd.remove(it); m_wd_to_path.remove(it->value); + if (::inotify_rm_watch(m_watcher_fd, it->value) < 0) + return Error::from_errno(errno); + dbgln_if(FILE_WATCHER_DEBUG, "remove_watch: stopped watching path '{}' on InodeWatcher {}", path, m_watcher_fd); return true; }