15using watcher_impl = watcher_wtr;
17using watcher_impl = watcher_fallback;
20auto get_watcher() -> watcher_impl&
22 static watcher_impl wd;
31 clock_t::duration poll_interval,
33 const std::string& watcher_name) -> std::uint64_t
35 auto& wd = get_watcher();
37 auto id = wd.watch_impl(path, filter, recursive, initial_list, poll_interval, std::move(callback), watcher_name);
47 auto& wd = get_watcher();
53 auto& wd = get_watcher();
54 wd.unwatch_all_impl();
57void watcher::touch(
const fs::path& path,
bool recursive, fs::file_time_type time)
60 if(fs::exists(path, err))
62 if(fs::is_directory(path, err))
66 for(
auto&
entry : fs::recursive_directory_iterator(path, err))
68 fs::last_write_time(
entry.path(), time, err);
73 for(
auto&
entry : fs::directory_iterator(path, err))
75 fs::last_write_time(
entry.path(), time, err);
78 fs::last_write_time(path, time, err);
82 fs::last_write_time(path, time, err);
89 auto& wd = get_watcher();
95 auto& wd = get_watcher();
101 static auto file_type_to_string = [](file_type
type) -> std::string
105 case file_type::regular:
107 case file_type::directory:
132 std::stringstream ss;
133 ss <<
"{\"" << int64_t(e.last_mod_time.time_since_epoch().count()) <<
"\":[";
136 ss << e.last_path <<
" -> ";
139 ss <<
"," << file_type_to_string(e.type);
140 ss <<
"," << status_to_string(e.status);
A filter that combines include and exclude patterns for file/directory filtering.
static void unwatch(std::uint64_t key)
Un-watches a previously registered file or directory.
static void resume()
Resumes all watchers.
std::function< void(const std::vector< entry > &, bool)> notify_callback
static void pause()
Pauses all watchers.
static void unwatch_all()
Un-watches all previously registered file or directory.
static void touch(const fs::path &path, bool recursive, fs::file_time_type time=fs::now())
Sets the last modification time of a file or directory. by default sets the time to the current time.
static auto watch(const fs::path &path, const pattern_filter &filter, bool recursive, bool initial_list, clock_t::duration poll_interval, notify_callback callback, const std::string &watcher_name="") -> std::uint64_t
Watches a file or directory for modification and call back the specified std::function....
auto to_string(const watcher::entry &e) -> std::string