Skip to content

Commit

Permalink
watcher: handle missing but absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Nov 22, 2023
1 parent ed83cd6 commit 4df8f8e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
9 changes: 6 additions & 3 deletions devel/include/wtr/watcher-/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<event>(*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} {};
Expand Down
33 changes: 16 additions & 17 deletions devel/include/wtr/watcher-/watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})}
{}

Expand Down
42 changes: 22 additions & 20 deletions include/wtr/watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<event>(*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} {};
Expand Down Expand Up @@ -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;
})}
{}

Expand Down

0 comments on commit 4df8f8e

Please sign in to comment.