Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen moved_to and moved_from events on Unix #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions FileWatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace filewatch {

FolderInfo _directory;

const std::uint32_t _listen_filters = IN_MODIFY | IN_CREATE | IN_DELETE;
const std::uint32_t _listen_filters = IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVE;

const static std::size_t event_size = (sizeof(struct inotify_event));
#endif // __unix__
Expand Down Expand Up @@ -604,7 +604,7 @@ namespace filewatch {
}
}();

const auto watch = inotify_add_watch(folder, watch_path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE);
const auto watch = inotify_add_watch(folder, watch_path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVE);
if (watch < 0)
{
throw std::system_error(errno, std::system_category());
Expand Down Expand Up @@ -644,6 +644,15 @@ namespace filewatch {
{
parsed_information.emplace_back(StringType{ changed_file }, Event::modified);
}
else if (event->mask & IN_MOVED_FROM)
{
parsed_information.emplace_back(T{ changed_file }, Event::renamed_old);
}
else if (event->mask & IN_MOVED_TO)
{
parsed_information.emplace_back(T{ changed_file }, Event::renamed_new);
}

}
}
i += event_size + event->len;
Expand Down