Skip to content

Commit 89de1cf

Browse files
author
Will
committed
tool/hone: amalgam
1 parent d6ba274 commit 89de1cf

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

include/wtr/watcher.hpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -548,37 +548,35 @@ struct sysres_type {
548548
argptr_type argptr{};
549549
};
550550

551+
/* We make a path from a C string...
552+
In an array, in a dictionary...
553+
Without type safety...
554+
Because most of darwin's apis are `void*`-typed.
555+
556+
We should be guarenteed that nothing in here is
557+
or can be null, but I'm skeptical. We ask Darwin
558+
for utf8 strings from a dictionary of utf8 strings
559+
which it gave us. Nothing should be able to be null.
560+
We'll check anyway, just in case Darwin lies.
561+
562+
The dictionary contains looks like this:
563+
{ "path": String
564+
, "fileID": Number
565+
}
566+
We can only call `CFStringGetCStringPtr()`
567+
on the `path` field. Not sure what function
568+
the `fileID` requires, or if it's different
569+
from what we'd get from `stat()`. (Is it an
570+
inode number?) Anyway, we seem to get this:
571+
-[__NSCFNumber length]: unrecognized ...
572+
Whenever we try to inspect it with Int or
573+
CStringPtr functions for CFStringGet...().
574+
The docs don't say much about these fields.
575+
I don't think they mention fileID at all.
576+
*/
551577
inline auto path_from_event_at(void* event_recv_paths, unsigned long i) noexcept
552578
-> std::filesystem::path
553579
{
554-
/* We make a path from a C string...
555-
In an array, in a dictionary...
556-
Without type safety...
557-
Because most of darwin's apis are `void*`-typed.
558-
559-
We should be guarenteed that nothing in here is
560-
or can be null, but I'm skeptical. We ask Darwin
561-
for utf8 strings from a dictionary of utf8 strings
562-
which it gave us. Nothing should be able to be null.
563-
We'll check anyway, just in case Darwin lies.
564-
565-
The dictionary contains looks like this:
566-
{ "path": String
567-
, "fileID": Number
568-
}
569-
We can only call `CFStringGetCStringPtr()`
570-
on the `path` field. Not sure what function
571-
the `fileID` requires, or if it's different
572-
from what we'd get from `stat()`. (Is it an
573-
inode number?) Anyway, we seem to get this:
574-
-[__NSCFNumber length]: unrecognized ...
575-
Whenever we try to inspect it with Int or
576-
CStringPtr functions for CFStringGet...().
577-
The docs don't say much about these fields.
578-
I don't think they mention fileID at all.
579-
*/
580-
namespace fs = std::filesystem;
581-
582580
if (event_recv_paths)
583581
if (
584582
void const* from_arr = CFArrayGetValueAtIndex(
@@ -592,8 +590,9 @@ inline auto path_from_event_at(void* event_recv_paths, unsigned long i) noexcept
592590
char const* as_cstr = CFStringGetCStringPtr(
593591
static_cast<CFStringRef>(from_dict),
594592
kCFStringEncodingUTF8))
595-
return fs::path{as_cstr};
596-
return fs::path{};
593+
return {as_cstr};
594+
595+
return {};
597596
}
598597

599598
inline auto event_recv_one(
@@ -604,12 +603,13 @@ inline auto event_recv_one(
604603
using path_type = enum ::wtr::watcher::event::path_type;
605604
using effect_type = enum ::wtr::watcher::event::effect_type;
606605

607-
if (
608-
! ctx // These checks are unfortunate
609-
|| ! ctx->callback // and absolutely necessary.
610-
|| ! ctx->seen_created_paths // Once in a while, Darwin will only
611-
|| ! ctx->last_rename_from_path // give *part* of the context to us.
612-
) [[unlikely]]
606+
auto ctx_ok =
607+
ctx // These checks are unfortunate
608+
&& ctx->callback // and absolutely necessary.
609+
&& ctx->seen_created_paths // Once in a while, Darwin will only
610+
&& ctx->last_rename_from_path; // give *part* of the context to us.
611+
612+
if (! ctx_ok) [[unlikely]]
613613
return;
614614

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

0 commit comments

Comments
 (0)