Skip to content

Commit

Permalink
tool/hone: amalgam
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Dec 3, 2023
1 parent 39eb040 commit 6f3932a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
1 change: 1 addition & 0 deletions devel/include/detail/wtr/watcher/adapter/darwin/watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ inline constexpr unsigned fsev_flag_effect_any
| fsev_flag_effect_remove
| fsev_flag_effect_modify
| fsev_flag_effect_rename;

// clang-format on

struct argptr_type {
Expand Down
79 changes: 44 additions & 35 deletions include/wtr/watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,36 @@ namespace watcher {
namespace adapter {
namespace {

// clang-format off
inline constexpr unsigned fsev_flag_path_file
= kFSEventStreamEventFlagItemIsFile;
inline constexpr unsigned fsev_flag_path_dir
= kFSEventStreamEventFlagItemIsDir;
inline constexpr unsigned fsev_flag_path_sym_link
= kFSEventStreamEventFlagItemIsSymlink;
inline constexpr unsigned fsev_flag_path_hard_link
= kFSEventStreamEventFlagItemIsHardlink
| kFSEventStreamEventFlagItemIsLastHardlink;
inline constexpr unsigned fsev_flag_effect_create
= kFSEventStreamEventFlagItemCreated;
inline constexpr unsigned fsev_flag_effect_remove
= kFSEventStreamEventFlagItemRemoved;
inline constexpr unsigned fsev_flag_effect_modify
= kFSEventStreamEventFlagItemModified
| kFSEventStreamEventFlagItemInodeMetaMod
| kFSEventStreamEventFlagItemFinderInfoMod
| kFSEventStreamEventFlagItemChangeOwner
| kFSEventStreamEventFlagItemXattrMod;
inline constexpr unsigned fsev_flag_effect_rename
= kFSEventStreamEventFlagItemRenamed;
inline constexpr unsigned fsev_flag_effect_any
= fsev_flag_effect_create
| fsev_flag_effect_remove
| fsev_flag_effect_modify
| fsev_flag_effect_rename;

// clang-format on

struct argptr_type {
using fspath = std::filesystem::path;
/* `fs::path` has no hash function, so we use this. */
Expand Down Expand Up @@ -567,43 +597,22 @@ inline auto path_from_event_at(void* event_recv_paths, unsigned long i) noexcept
}

inline auto event_recv_one(
argptr_type& ctx,
argptr_type* ctx,
std::filesystem::path const& path,
unsigned flags)
{
namespace fs = std::filesystem;

using path_type = enum ::wtr::watcher::event::path_type;
using effect_type = enum ::wtr::watcher::event::effect_type;

static constexpr unsigned fsev_flag_path_file =
kFSEventStreamEventFlagItemIsFile;
static constexpr unsigned fsev_flag_path_dir =
kFSEventStreamEventFlagItemIsDir;
static constexpr unsigned fsev_flag_path_sym_link =
kFSEventStreamEventFlagItemIsSymlink;
static constexpr unsigned fsev_flag_path_hard_link =
kFSEventStreamEventFlagItemIsHardlink
| kFSEventStreamEventFlagItemIsLastHardlink;

static constexpr unsigned fsev_flag_effect_create =
kFSEventStreamEventFlagItemCreated;
static constexpr unsigned fsev_flag_effect_remove =
kFSEventStreamEventFlagItemRemoved;
static constexpr unsigned fsev_flag_effect_modify =
kFSEventStreamEventFlagItemModified
| kFSEventStreamEventFlagItemInodeMetaMod
| kFSEventStreamEventFlagItemFinderInfoMod
| kFSEventStreamEventFlagItemChangeOwner
| kFSEventStreamEventFlagItemXattrMod;
static constexpr unsigned fsev_flag_effect_rename =
kFSEventStreamEventFlagItemRenamed;

static constexpr unsigned fsev_flag_effect_any =
fsev_flag_effect_create | fsev_flag_effect_remove | fsev_flag_effect_modify
| fsev_flag_effect_rename;

auto [callback, sc_paths, lrf_path] = ctx;
if (
! ctx // These checks are unfortunate
|| ! ctx->callback // and absolutely necessary.
|| ! ctx->seen_created_paths // Once in a while, Darwin will only
|| ! ctx->last_rename_from_path // give *part* of the context to us.
) [[unlikely]]
return;

auto [callback, sc_paths, lrf_path] = *ctx;

auto path_str = path.string();

Expand Down Expand Up @@ -705,10 +714,10 @@ inline auto event_recv(
FSEventStreamEventId const* /* event stream id */
) noexcept -> void
{
if (! ctx || ! paths || ! flags) return;
auto& ap = *static_cast<argptr_type*>(ctx);
for (unsigned long i = 0; i < count; i++)
event_recv_one(ap, path_from_event_at(paths, i), flags[i]);
auto ap = static_cast<argptr_type*>(ctx);
if (paths && flags)
for (unsigned long i = 0; i < count; i++)
event_recv_one(ap, path_from_event_at(paths, i), flags[i]);
}

/* Make sure that event_recv has the same type as, or is
Expand Down

0 comments on commit 6f3932a

Please sign in to comment.