33 Watcher(
const std::string &file_name, std::chrono::duration<float> to = 0s)
34 : _file_name(file_name), _timeout(to) {
36 _fd = open(_file_name.c_str(), O_EVTONLY);
38 std::chrono::duration_cast<std::chrono::seconds>(_timeout).count();
40 std::chrono::duration_cast<std::chrono::nanoseconds>(_timeout).count() %
42 EV_SET(&_change, _fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
43 NOTE_WRITE, 0, (
void *)_file_name.c_str());
44#elif defined(__linux__)
45 _inotify_fd = inotify_init1(IN_NONBLOCK);
46 _watch = inotify_add_watch(_inotify_fd, _file_name.c_str(), IN_MODIFY);
49 std::chrono::duration_cast<std::chrono::milliseconds>(_timeout).count();
51 fs::path file_path(_file_name);
52 std::string dir_path = file_path.parent_path().string();
53 if (dir_path.empty()) dir_path =
".";
54 _change_handle = FindFirstChangeNotificationA(
55 dir_path.c_str(), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
56 _last_change_time = std::chrono::steady_clock::now() - std::chrono::seconds(1);
131 return kevent(_kq, &_change, 1, &_event, 1, &_ts);
135 return kevent(_kq, &_change, 1, &_event, 1, &ts);