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.
This commit is contained in:
Timothy Flynn 2024-08-23 10:04:17 -04:00 committed by Andreas Kling
parent 61419cf717
commit abc462999e
Notes: github-actions[bot] 2024-08-25 07:49:10 +00:00

View file

@ -164,12 +164,12 @@ ErrorOr<bool> 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;
}