Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix MacOs issue in case multi instance of same class is used #51 #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 42 additions & 23 deletions FileWatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,29 +1117,48 @@ namespace filewatch {
_cv.notify_all();
}

static void handleFsEvent(__attribute__((unused)) ConstFSEventStreamRef streamFef,
void* clientCallBackInfo,
size_t numEvents,
CFArrayRef eventPaths,
const FSEventStreamEventFlags* eventFlags,
__attribute__((unused)) const FSEventStreamEventId* eventIds) {
FileWatch<StringType>* self = (FileWatch<StringType>*)clientCallBackInfo;

for (size_t i = 0; i < numEvents; i++) {
FSEventStreamEventFlags flag = eventFlags[i];
CFStringRef path = (CFStringRef)CFArrayGetValueAtIndex(eventPaths, i);

if (self->_watching_single_file) {
self->seeSingleFileChanges();
}
else if (flag & kFSEventStreamEventFlagMustScanSubDirs) {
self->walkAndSeeChanges();
}
else {
self->notify(path, flag);
}
}
}
static void handleFsEvent(__attribute__((unused)) ConstFSEventStreamRef streamFef,
void *clientCallBackInfo,
size_t numEvents,
CFArrayRef eventPaths,
const FSEventStreamEventFlags *eventFlags,
__attribute__((unused)) const FSEventStreamEventId *eventIds)
{
FileWatch<StringType> *self = (FileWatch<StringType> *)clientCallBackInfo;

for (size_t i = 0; i < numEvents; i++)
{
FSEventStreamEventFlags flag = eventFlags[i];
CFStringRef path = (CFStringRef)CFArrayGetValueAtIndex(eventPaths, i);

// Convert CFStringRef to StringType
CFIndex pathLength = CFStringGetLength(path);
char buffer[PATH_MAX + 1];
CFStringGetCString(path, buffer, PATH_MAX, IsWChar<C>::value ? kCFStringEncodingUTF32 : kCFStringEncodingUTF8);
StringType absolutePath = StringType { (const C *)buffer, static_cast<size_t>(pathLength) };
PathParts pathPair = self->splitPath(absolutePath);

// Ensure the event belongs to the monitored file or directory
if (self->_watching_single_file)
{
if (pathPair.filename == self->_filename)
{
self->seeSingleFileChanges();
}
}
else if (flag & kFSEventStreamEventFlagMustScanSubDirs)
{
if (isInDirectory(absolutePath, self->_path))
{
self->walkAndSeeChanges();
}
}
else
{
self->notify(path, flag);
}
}
}

FSEventStreamRef openStream(const StringType& directory) {
CFStringEncoding encoding = IsWChar<C>::value?
Expand Down