Skip to content

Commit

Permalink
fix(fsevents): allow on older mac sdk's
Browse files Browse the repository at this point in the history
mainly useful for nixos on macos which is stuck on the old sdk

Signed-off-by: Rudi Grinberg <[email protected]>

ps-id: 32403256-aef1-41bb-b674-272998e51c3c
  • Loading branch information
rgrinberg authored and emillon committed Oct 13, 2022
1 parent 19a3214 commit 8ed5e79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
3.5.0 (unreleased)
------------------

- Enable file watching on MacOS SDK < 10.13. (#6218, @rgrinberg)

- Sandbox running cinaps actions starting from cinaps 1.1 (#6176, @rgrinberg)

- Add a `runtime_deps` field in the `cinaps` stanza to specify runtime
Expand Down
19 changes: 12 additions & 7 deletions src/fsevents/fsevents_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#include <caml/threads.h>

#if defined(__APPLE__)
#include <Availability.h>
#endif

#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
#include <Availability.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>

Expand Down Expand Up @@ -89,9 +87,13 @@ static void dune_fsevents_callback(const FSEventStreamRef streamRef,
if (!(interesting_flags & flags)) {
continue;
}
CFStringRef cf_path;
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
CFDictionaryRef details = CFArrayGetValueAtIndex(eventPaths, i);
CFStringRef cf_path =
CFDictionaryGetValue(details, kFSEventStreamEventExtendedDataPathKey);
cf_path = CFDictionaryGetValue(details, kFSEventStreamEventExtendedDataPathKey);
#else
cf_path = (CFStringRef) CFArrayGetValueAtIndex(eventPaths, i);
#endif
CFIndex len = CFStringGetLength(cf_path);
CFIndex byte_len;
CFIndex res =
Expand Down Expand Up @@ -152,7 +154,9 @@ CAMLprim value dune_fsevents_create(value v_paths, value v_latency,

const FSEventStreamEventFlags flags =
kFSEventStreamCreateFlagNoDefer |
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
kFSEventStreamCreateFlagUseExtendedData |
#endif
kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagFileEvents;

dune_fsevents_t *t;
Expand Down Expand Up @@ -316,7 +320,9 @@ static const FSEventStreamEventFlags all_flags[] = {
kFSEventStreamEventFlagOwnEvent,
kFSEventStreamEventFlagItemIsHardlink,
kFSEventStreamEventFlagItemIsLastHardlink,
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
kFSEventStreamEventFlagItemCloned,
#endif
};

CAMLprim value dune_fsevents_raw(value v_flags) {
Expand All @@ -338,8 +344,7 @@ CAMLprim value dune_fsevents_available(value unit) {

#else

static char *unavailable_message =
"fsevents is only available on macos >= 10.13";
static char *unavailable_message = "fsevents is only available on macos";

CAMLprim value dune_fsevents_stop(value v_t) {
caml_failwith(unavailable_message);
Expand Down

0 comments on commit 8ed5e79

Please sign in to comment.