Inotify 删除事件丢失
Inotify Delete Events are missing
删除同一目录下的文件时,事件丢失。
inotify监控目录:./test
删除命令:rm -rf ./test/*
文件数:20;
但是事件通知12,这是怎么回事?
int fileDescripter = inotify_init();
char buffer[BUF_LEN];
int watchDescripter = inotify_add_watch(fileDescripter, path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE);
while(true)
{
read(fileDescripter, buffer, BUF_LEN);
struct inotify_event *evt_inotify = (struct inotify_event*) &buffer;
string filename(evt_inotify->name);
cout << " CATCH : " << path+"/"+filename << endl;
if(evt_inotify->len){
if(evt_inotify->mask & IN_CREATE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR CREATE" << endl;
}
else
{
cout << "FILE CREATE" << endl;
}
}
else if(evt_inotify->mask & IN_DELETE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR DELETE" << endl;
}
else
{
cout << "FILE DELETE" << endl;
}
}
else if(evt_inotify->mask & IN_MODIFY)
{
if(evt_inotify->mask & IN_ISDIR)
{
}
else
{
}
}
}
}\
在第12行,打印的是event notify count(12)
我解决了
inotify_init是阻塞模式,inotify_init1(IN_NONBLOCK)使用.
inotify_init读时需要锁
删除同一目录下的文件时,事件丢失。
inotify监控目录:./test 删除命令:rm -rf ./test/*
文件数:20;
但是事件通知12,这是怎么回事?
int fileDescripter = inotify_init();
char buffer[BUF_LEN];
int watchDescripter = inotify_add_watch(fileDescripter, path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE);
while(true)
{
read(fileDescripter, buffer, BUF_LEN);
struct inotify_event *evt_inotify = (struct inotify_event*) &buffer;
string filename(evt_inotify->name);
cout << " CATCH : " << path+"/"+filename << endl;
if(evt_inotify->len){
if(evt_inotify->mask & IN_CREATE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR CREATE" << endl;
}
else
{
cout << "FILE CREATE" << endl;
}
}
else if(evt_inotify->mask & IN_DELETE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR DELETE" << endl;
}
else
{
cout << "FILE DELETE" << endl;
}
}
else if(evt_inotify->mask & IN_MODIFY)
{
if(evt_inotify->mask & IN_ISDIR)
{
}
else
{
}
}
}
}\
在第12行,打印的是event notify count(12)
我解决了
inotify_init是阻塞模式,inotify_init1(IN_NONBLOCK)使用.
inotify_init读时需要锁