我想在 mac 上使用 FSEvent 监控目录。
此错误是在根上下文中生成的。如果我在用户上下文中运行程序,它会正常工作。
错误是: FSEventStreamCreate: _FSEventStreamCreate: ERROR: watch_path() failed for some_path.
我想观看路径数组。 但创建流失败。
它在根路径数量较少的情况下工作正常。
我用来创建流的代码是。
FSEventStreamContext * streamContext = (FSEventStreamContext *)malloc(sizeof(FSEventStreamContext));
streamContext->version = 0;
streamContext->info = NULL;//&fileDescriptor;
streamContext->retain = NULL;
streamContext->release = NULL;
streamContext->copyDescription = NULL;
/* Create the stream, passing in a callback */
stream = FSEventStreamCreate(
NULL,
&myCallbackFunction,
streamContext,
pathsToWatch, /* This is the array of paths I am passing to watch, It work fine in user context for large number of objects too. */
kFSEventStreamEventIdSinceNow, /* Or a previous event ID */
latency,
kFSEventStreamCreateFlagNone | kFSEventStreamCreateFlagWatchRoot /* Flags explained in reference */
);
if (NULL == stream) /* Stream get NULL */
{
NSLog(@"Ruturning False : stream == NULL");
NSLog(@"FSEventStreamCreate failed");
return;
}
提前致谢。
最佳答案
kFSEventStreamCreateFlagWatchRoot
函数 FSEventStreamCreate()
中的标志导致问题,我不知道为什么。
但是,当我删除该标志时,它也会在根上下文和用户上下文中运行许多路径。
关于c++ - FSEvent 无法在根上下文 : Error: FSEventStreamCreate: _FSEventStreamCreate: ERROR: watch_path() failed for 中创建流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27041728/