summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpierre lamot <pierre.lamot@openwide.fr>2015-03-03 17:01:03 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 10:42:51 +0100
commitde767cabfaf84f262c785ce468508f6ed52cc009 (patch)
tree880db66d1636587a6b8a29a3fc44ff88375eeb6a /src
parentc380812496f226d6d3243a2b1c083f6aed8a4dc9 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/lib/eio/eio_monitor_cocoa.c22
-rw-r--r--src/tests/eio/eio_test_monitor.c80
2 files changed, 92 insertions, 10 deletions
diff --git a/src/lib/eio/eio_monitor_cocoa.c b/src/lib/eio/eio_monitor_cocoa.c
index ea1d793..8cadeaf 100644
--- a/src/lib/eio/eio_monitor_cocoa.c
+++ b/src/lib/eio/eio_monitor_cocoa.c
@@ -195,7 +195,6 @@ _eio_get_monitor_path(const char *path, char **monpath, char **fullpath)
195 char realPath[PATH_MAX]; 195 char realPath[PATH_MAX];
196 char *realPathOk; 196 char *realPathOk;
197 char *dname = NULL; 197 char *dname = NULL;
198 char *fname = NULL;
199 struct stat sb; 198 struct stat sb;
200 199
201 realPathOk = realpath(path, realPath); 200 realPathOk = realpath(path, realPath);
@@ -383,15 +382,18 @@ void eio_monitor_backend_del(Eio_Monitor *monitor)
383 CFArrayRemoveValueAtIndex(_paths_to_watch, idx); 382 CFArrayRemoveValueAtIndex(_paths_to_watch, idx);
384 } 383 }
385 384
386 _stream = FSEventStreamCreate(NULL, 385 if (CFArrayGetCount(_paths_to_watch) > 0)
387 _eio_fsevent_cb, 386 {
388 NULL, 387 _stream = FSEventStreamCreate(NULL,
389 _paths_to_watch, 388 _eio_fsevent_cb,
390 eventid, 389 NULL,
391 _latency, 390 _paths_to_watch,
392 kFSEventStreamCreateFlagFileEvents 391 eventid,
393 | kFSEventStreamCreateFlagNoDefer 392 _latency,
394 ); 393 kFSEventStreamCreateFlagFileEvents
394 | kFSEventStreamCreateFlagNoDefer
395 );
396 }
395 backend = monitor->backend; 397 backend = monitor->backend;
396 monitor->backend = NULL; 398 monitor->backend = NULL;
397 if (!backend) return; 399 if (!backend) return;
diff --git a/src/tests/eio/eio_test_monitor.c b/src/tests/eio/eio_test_monitor.c
index 378c427..ba5943f 100644
--- a/src/tests/eio/eio_test_monitor.c
+++ b/src/tests/eio/eio_test_monitor.c
@@ -135,6 +135,82 @@ static void _common_shutdown(Eina_Tmpstr *dirname)
135 135
136/////// tests monitoring a directory 136/////// tests monitoring a directory
137 137
138START_TEST(eio_test_monitor_add_and_remove)
139{
140 Eina_Tmpstr *dirname = _common_init();
141 Eina_Stringshare *filename;
142 Eio_Monitor *monitor;
143
144 filename = eina_stringshare_printf("%s/eio_test_monitor_directory_file_created_notify", dirname);
145 _create_directory((void*)filename);
146
147 //sleep to avoid catching event generated by above manipulations
148 usleep(500000);
149
150 //monitor directory
151 monitor = eio_monitor_add(filename);
152
153 usleep(500000);
154
155 eio_monitor_del(monitor);
156
157 _common_shutdown(dirname);
158}
159END_TEST
160
161START_TEST(eio_test_monitor_add_remove_add)
162{
163 Eina_Tmpstr *dirname = _common_init();
164 Eina_Stringshare *filename;
165 Eio_Monitor *monitor1;
166 Eio_Monitor *monitor2;
167
168 filename = eina_stringshare_printf("%s/eio_test_monitor_add_remove_add", dirname);
169 _create_directory((void*)filename);
170
171 //sleep to avoid catching event generated by above manipulations
172 usleep(500000);
173
174 //monitor directory
175 monitor1 = eio_monitor_add(filename);
176 eio_monitor_del(monitor1);
177
178 usleep(500000);
179
180 monitor2 = eio_monitor_add(filename);
181 eio_monitor_del(monitor2);
182
183 _common_shutdown(dirname);
184}
185END_TEST
186
187START_TEST(eio_test_monitor_add_add_remove_remove)
188{
189 Eina_Tmpstr *dirname = _common_init();
190 Eina_Stringshare *filename1;
191 Eina_Stringshare *filename2;
192 Eio_Monitor *monitor1;
193 Eio_Monitor *monitor2;
194
195 filename1 = eina_stringshare_printf("%s/eio_test_monitor_add_add_remove_remove", dirname);
196 filename2 = eina_stringshare_printf("%s/eio_test_monitor_add_add_remove_remove", dirname);
197 _create_directory((void*)filename1);
198 _create_directory((void*)filename2);
199
200 //sleep to avoid catching event generated by above manipulations
201 usleep(500000);
202
203 //monitor directory
204 monitor1 = eio_monitor_add(filename1);
205 monitor2 = eio_monitor_add(filename2);
206 usleep(500000);
207 eio_monitor_del(monitor2);
208 eio_monitor_del(monitor1);
209
210 _common_shutdown(dirname);
211}
212END_TEST
213
138static void _file_created_cb(void *data, int type, void *event) 214static void _file_created_cb(void *data, int type, void *event)
139{ 215{
140 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CREATED); 216 ck_assert_int_eq(type, (int)EIO_MONITOR_FILE_CREATED);
@@ -650,6 +726,10 @@ END_TEST
650 726
651void eio_test_monitor(TCase *tc) 727void eio_test_monitor(TCase *tc)
652{ 728{
729 tcase_add_test(tc, eio_test_monitor_add_and_remove);
730 tcase_add_test(tc, eio_test_monitor_add_remove_add);
731 tcase_add_test(tc, eio_test_monitor_add_add_remove_remove);
732
653 tcase_add_test(tc, eio_test_monitor_directory_file_created_notify); 733 tcase_add_test(tc, eio_test_monitor_directory_file_created_notify);
654 tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify); 734 tcase_add_test(tc, eio_test_monitor_directory_file_deleted_notify);
655 tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify); 735 tcase_add_test(tc, eio_test_monitor_directory_file_modified_notify);