eio: don't restart a monitor on MacOSX when every paths have been removed.

This patch check that when a monitor is removed the FSEvent service, it is
not restarted if there is no more paths to monitor. This was generating an
error message from FSEvent.

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
pierre lamot 2015-03-03 17:01:03 +01:00 committed by Cedric BAIL
parent c380812496
commit de767cabfa
2 changed files with 92 additions and 10 deletions

View File

@ -195,7 +195,6 @@ _eio_get_monitor_path(const char *path, char **monpath, char **fullpath)
char realPath[PATH_MAX];
char *realPathOk;
char *dname = NULL;
char *fname = NULL;
struct stat sb;
realPathOk = realpath(path, realPath);
@ -383,15 +382,18 @@ void eio_monitor_backend_del(Eio_Monitor *monitor)
CFArrayRemoveValueAtIndex(_paths_to_watch, idx);
}
_stream = FSEventStreamCreate(NULL,
_eio_fsevent_cb,
NULL,
_paths_to_watch,
eventid,
_latency,
kFSEventStreamCreateFlagFileEvents
| kFSEventStreamCreateFlagNoDefer
);
if (CFArrayGetCount(_paths_to_watch) > 0)
{
_stream = FSEventStreamCreate(NULL,
_eio_fsevent_cb,
NULL,
_paths_to_watch,
eventid,
_latency,
kFSEventStreamCreateFlagFileEvents
| kFSEventStreamCreateFlagNoDefer
);
}
backend = monitor->backend;
monitor->backend = NULL;
if (!backend) return;

View File

@ -135,6 +135,82 @@ static void _common_shutdown(Eina_Tmpstr *dirname)
/////// tests monitoring a directory
START_TEST(eio_test_monitor_add_and_remove)
{
Eina_Tmpstr *dirname = _common_init();
Eina_Stringshare *filename;
Eio_Monitor *monitor;
filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_created_notify", dirname);
_create_directory((void*)filename);
//sleep to avoid catching event generated by above manipulations
usleep(500000);
//monitor directory
monitor = eio_monitor_add(filename);
usleep(500000);
eio_monitor_del(monitor);
_common_shutdown(dirname);
}
END_TEST
START_TEST(eio_test_monitor_add_remove_add)
{
Eina_Tmpstr *dirname = _common_init();
Eina_Stringshare *filename;
Eio_Monitor *monitor1;
Eio_Monitor *monitor2;
filename = eina_stringshare_printf("%s/eio_test_monitor_add_remove_add", dirname);
_create_directory((void*)filename);
//sleep to avoid catching event generated by above manipulations
usleep(500000);
//monitor directory
monitor1 = eio_monitor_add(filename);
eio_monitor_del(monitor1);
usleep(500000);
monitor2 = eio_monitor_add(filename);
eio_monitor_del(monitor2);
_common_shutdown(dirname);
}
END_TEST
START_TEST(eio_test_monitor_add_add_remove_remove)
{
Eina_Tmpstr *dirname = _common_init();
Eina_Stringshare *filename1;
Eina_Stringshare *filename2;
Eio_Monitor *monitor1;
Eio_Monitor *monitor2;
filename1 = eina_stringshare_printf("%s/eio_test_monitor_add_add_remove_remove", dirname);
filename2 = eina_stringshare_printf("%s/eio_test_monitor_add_add_remove_remove", dirname);
_create_directory((void*)filename1);
_create_directory((void*)filename2);
//sleep to avoid catching event generated by above manipulations
usleep(500000);
//monitor directory
monitor1 = eio_monitor_add(filename1);
monitor2 = eio_monitor_add(filename2);
usleep(500000);
eio_monitor_del(monitor2);
eio_monitor_del(monitor1);
_common_shutdown(dirname);
}
END_TEST
static void _file_created_cb(void *data, int type, void *event)
{
ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CREATED);
@ -650,6 +726,10 @@ END_TEST
void eio_test_monitor(TCase *tc)
{
tcase_add_test(tc, eio_test_monitor_add_and_remove);
tcase_add_test(tc, eio_test_monitor_add_remove_add);
tcase_add_test(tc, eio_test_monitor_add_add_remove_remove);
tcase_add_test(tc, eio_test_monitor_directory_file_created_notify);
tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify);
tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify);