在 OSX 10.8.x 上,我使用 FSEvents 来检测目录中的更改。问题是当通过 sftp 复制文件时,不会调用 FSEvents 回调。
当我cp
用来复制文件(或touch
模拟更改)时,会调用回调。我在做傻事吗?sshd 是否使用某种低级 API 来创建文件?我应该向 Apple 提交错误吗?
eventQueue = dispatch_queue_create(EVENT_QUEUE_NAME, DISPATCH_QUEUE_SERIAL);
//Watch the data/apns directory (for .json files)
NSString *pathToWatch = ...
NSArray *pathsToWatch = @[pathToWatch];
CFAbsoluteTime latency = 1.0; /* Latency in seconds */
// Create the FileSystem events stream, passing in a callback
streamRef = FSEventStreamCreate(NULL,
&fscallback,
NULL,
(__bridge CFArrayRef)(pathsToWatch),
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagIgnoreSelf);
if (streamRef)
{
FSEventStreamSetDispatchQueue(streamRef, eventQueue);
if (NO == FSEventStreamStart(streamRef))
{
DDLogError(@"FSEventStreamStart error");
}
else
{
DDLogError(@"FSEventStreamStart ok");
}
}
else
{
DDLogError(@"FSEventStreamCreate error");
}
我在 sshd 配置中使用 internal-sftp:
...
Subsystem sftp internal-sftp
Match Group users
PasswordAuthentication yes
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
Match User user
ChrootDirectory /vhosts/web/user