我想使用 FSEvent 监视 mac 上的目录。
此错误是在根上下文中生成的。如果我在用户上下文中运行程序,它可以正常工作。
错误是: FSEventStreamCreate:_FSEventStreamCreate:错误:some_path 的 watch_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;
}
提前致谢。