diff --git a/devel/include/wtr/watcher-/event.hpp b/devel/include/wtr/watcher-/event.hpp index 4ad0238f..ce6aaad3 100644 --- a/devel/include/wtr/watcher-/event.hpp +++ b/devel/include/wtr/watcher-/event.hpp @@ -102,12 +102,15 @@ struct event { : path_name{from.path_name} , effect_type{from.effect_type} , path_type{from.path_type} - , effect_time{from.effect_time} {}; + , effect_time{from.effect_time} + , associated{ + from.associated ? std::make_unique(*from.associated) + : nullptr} {}; inline event( std::filesystem::path const& path_name, - enum effect_type const& effect_type, - enum path_type const& path_type) noexcept + enum effect_type effect_type, + enum path_type path_type) noexcept : path_name{path_name} , effect_type{effect_type} , path_type{path_type} {}; diff --git a/devel/include/wtr/watcher-/watch.hpp b/devel/include/wtr/watcher-/watch.hpp index 340e4826..70143d73 100644 --- a/devel/include/wtr/watcher-/watch.hpp +++ b/devel/include/wtr/watcher-/watch.hpp @@ -60,25 +60,24 @@ class watch { std::launch::async, [this, path, callback] { - auto abs_path_ec = std::error_code{}; - auto abs_path = std::filesystem::absolute(path, abs_path_ec); + auto ec = std::error_code{}; + auto abs_path = std::filesystem::absolute(path, ec); + auto path_ok = + ! ec && std::filesystem::is_directory(abs_path, ec) && ! ec; callback( - {(abs_path_ec ? "e/self/live@" : "s/self/live@") - + abs_path.string(), - ::wtr::watcher::event::effect_type::create, - ::wtr::watcher::event::path_type::watcher}); - auto watched_and_died_ok = abs_path_ec - ? false - : ::detail::wtr::watcher::adapter::watch( - abs_path, - callback, - this->is_living); + {(path_ok ? "s/self/live@" : "e/self/live@") + abs_path.string(), + event::effect_type::create, + event::path_type::watcher}); + auto died_ok = ! path_ok ? true + : ::detail::wtr::watcher::adapter::watch( + abs_path, + callback, + this->is_living); callback( - {(watched_and_died_ok ? "s/self/die@" : "e/self/die@") - + abs_path.string(), - ::wtr::watcher::event::effect_type::destroy, - ::wtr::watcher::event::path_type::watcher}); - return watched_and_died_ok; + {(died_ok ? "s/self/die@" : "e/self/die@") + abs_path.string(), + event::effect_type::destroy, + event::path_type::watcher}); + return path_ok && died_ok; })} {} diff --git a/include/wtr/watcher.hpp b/include/wtr/watcher.hpp index 09eaeaae..249fc21d 100644 --- a/include/wtr/watcher.hpp +++ b/include/wtr/watcher.hpp @@ -103,12 +103,15 @@ struct event { : path_name{from.path_name} , effect_type{from.effect_type} , path_type{from.path_type} - , effect_time{from.effect_time} {}; + , effect_time{from.effect_time} + , associated{ + from.associated ? std::make_unique(*from.associated) + : nullptr} {}; inline event( std::filesystem::path const& path_name, - enum effect_type const& effect_type, - enum path_type const& path_type) noexcept + enum effect_type effect_type, + enum path_type path_type) noexcept : path_name{path_name} , effect_type{effect_type} , path_type{path_type} {}; @@ -2130,25 +2133,24 @@ class watch { std::launch::async, [this, path, callback] { - auto abs_path_ec = std::error_code{}; - auto abs_path = std::filesystem::absolute(path, abs_path_ec); + auto ec = std::error_code{}; + auto abs_path = std::filesystem::absolute(path, ec); + auto path_ok = + ! ec && std::filesystem::is_directory(abs_path, ec) && ! ec; callback( - {(abs_path_ec ? "e/self/live@" : "s/self/live@") - + abs_path.string(), - ::wtr::watcher::event::effect_type::create, - ::wtr::watcher::event::path_type::watcher}); - auto watched_and_died_ok = abs_path_ec - ? false - : ::detail::wtr::watcher::adapter::watch( - abs_path, - callback, - this->is_living); + {(path_ok ? "s/self/live@" : "e/self/live@") + abs_path.string(), + event::effect_type::create, + event::path_type::watcher}); + auto died_ok = ! path_ok ? true + : ::detail::wtr::watcher::adapter::watch( + abs_path, + callback, + this->is_living); callback( - {(watched_and_died_ok ? "s/self/die@" : "e/self/die@") - + abs_path.string(), - ::wtr::watcher::event::effect_type::destroy, - ::wtr::watcher::event::path_type::watcher}); - return watched_and_died_ok; + {(died_ok ? "s/self/die@" : "e/self/die@") + abs_path.string(), + event::effect_type::destroy, + event::path_type::watcher}); + return path_ok && died_ok; })} {}