Я пытаюсь рекурсивно отслеживать каталог в Linux с помощью inotify. Я использую метод select в своем приложении для мониторинга изменений каталога. Я получаю уведомление обо всех событиях, кроме удаления. Когда я удаляю каталог, используя команду rm, мой метод select не работает.метод select не работает, когда происходит событие IN_DELETE inotify
я получаю следующее сообщение об ошибке «ошибочными или неполными многобайтовую или широкий характер»
Как я могу решить эту проблему.
Спасибо за ответ
fd = inotify_init();
struct timeval time;
fd_set rfds;
int ret;
/* timeout after five seconds */
time.tv_sec = 5;
time.tv_usec = 0;
/* zero-out the fd_set */
FD_ZERO (&rfds);
/*
* add the inotify fd to the fd_set -- of course,
* your application will probably want to add
* other file descriptors here, too
*/
FD_SET (fd, &rfds);
ret = select (fd + 1, &rfds, NULL, NULL, &time);
if (ret < 0)
perror ("select");
else if (!ret)
/* timed out! */
else if (FD_ISSET (fd, &rfds)
/* inotify events are available! */
{
// inotify events are available
len = read(fd, buf, EVENT_BUF_LEN);
if(len <= 0)
{
qDebug()<<"Error : read failed..";
perror("read : ");
}
while(i < len)
{
struct inotify_event *event;
event = (struct inotify_event *) &buf[i];
eventNotification(event);
i += EVENT_SIZE + event->len;
count++;
}
}
void eventNotification (struct inotify_event *event)
{
if (event->len)
{
if (event->mask & IN_CREATE)
{
if (event->mask & IN_ISDIR)
{
printf("The directory %s was created.\n", event->name);
}
else
{
printf("The file %s was created.\n", event->name);
}
}
else if (event->mask & IN_DELETE)
{
if (event->mask & IN_ISDIR)
{
printf("The directory %s was deleted.\n", event->name);
}
else
{
printf("The file %s was deleted.\n", event->name);
}
}
else if (event->mask & IN_MODIFY)
{
if (event->mask & IN_ISDIR)
{
printf("The directory %s was modified.\n", event->name);
}
else
{
printf("The file %s was modified.\n", event->name);
}
}
}
}