event/InotifyEvent: add method TryAddWatch()

This commit is contained in:
Max Kellermann 2023-10-13 18:29:16 +02:00 committed by Max Kellermann
parent db5f270f42
commit 7c0b561a16
2 changed files with 14 additions and 2 deletions

View File

@ -34,11 +34,17 @@ InotifyEvent::~InotifyEvent() noexcept
Close();
}
int
InotifyEvent::TryAddWatch(const char *pathname, uint32_t mask) noexcept
{
return inotify_add_watch(event.GetFileDescriptor().Get(),
pathname, mask);
}
int
InotifyEvent::AddWatch(const char *pathname, uint32_t mask)
{
int wd = inotify_add_watch(event.GetFileDescriptor().Get(),
pathname, mask);
int wd = TryAddWatch(pathname, mask);
if (wd < 0)
throw FmtErrno("inotify_add_watch('{}') failed", pathname);

View File

@ -84,6 +84,12 @@ public:
*/
int AddWatch(const char *pathname, uint32_t mask);
/**
* Like AddWatch(), but returns -1 instead of throwing on
* error.
*/
int TryAddWatch(const char *pathname, uint32_t mask) noexcept;
/**
* Wrapper for AddWatch(pathname, IN_MODIFY).
*/