Skip to content

Commit

Permalink
event/InotifyEvent: add method TryAddWatch()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Oct 13, 2023
1 parent 8075055 commit 2b737aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/event/InotifyEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/event/InotifyEvent.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down

0 comments on commit 2b737aa

Please sign in to comment.