From: Marcel Hollerbach Date: Tue, 2 Apr 2019 12:50:34 +0000 (-0400) Subject: efl_io_model: start early on monitoring X-Git-Tag: accepted/tizen/unified/20190410.002130~41 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cea0c3cbfb6d424b9f4dc27aef89e07b1b57050;p=platform%2Fupstream%2Fefl.git efl_io_model: start early on monitoring Summary: Little introduction into what eio did before this commit: Efl.Io.Model creation: - direct ls of a directory in a thread (A) - take all the contents of a directory and feed it slowly back into the mainloop - when all events have been feeded back to the mainloop and have been processed: start monitoring (B) However, any file created between (A) and (B) will not be in the model, since not the listing nor the monitoring did caputure it. Hence we need to start monitoring before we actaully start listing. In the callbacks we then check if we already published something. ref T7311 Reviewers: zmike, cedric Reviewed By: cedric Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T7311 Differential Revision: https://phab.enlightenment.org/D8525 --- diff --git a/src/lib/eio/efl_io_model.c b/src/lib/eio/efl_io_model.c index f023ea7..300dac0 100644 --- a/src/lib/eio/efl_io_model.c +++ b/src/lib/eio/efl_io_model.c @@ -57,6 +57,21 @@ _eio_file_error_cb(void *data, Eio_File *handler, int error) pd->request.move = NULL; } + +static Eina_Bool +_already_added(Efl_Io_Model_Data *pd, const char *path) +{ + Efl_Io_Model_Info *mi; + Eina_List *node; + + EINA_LIST_FOREACH(pd->files, node, mi) + { + if (!strcmp(mi->path, path)) + return EINA_TRUE; + } + return EINA_FALSE; +} + /** * Callbacks * Ecore Events @@ -78,6 +93,9 @@ _efl_model_evt_added_ecore_cb(void *data, int type, void *event) if (ev->monitor != pd->monitor) return EINA_TRUE; + if (_already_added(pd, ev->filename)) + return EINA_TRUE; + obj = pd->self; path = ecore_file_dir_get(ev->filename); @@ -704,6 +722,8 @@ _efl_io_model_children_list(void *data, Eina_Array *entries) { Efl_Io_Model_Info *mi; + if (_already_added(pd, info->path)) continue; + if (pd->filter.cb) { if (!pd->filter.cb(pd->filter.data, obj, info)) @@ -733,18 +753,6 @@ _efl_io_model_children_list(void *data, Eina_Array *entries) efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, NULL); } -static Eina_Value -_efl_io_model_children_list_on(Eo *o EINA_UNUSED, void *data, const Eina_Value v) -{ - Efl_Io_Model_Data *pd = data; - - // Now that we have listed the content of the directory, - // we can whatch over it - _efl_io_model_efl_model_monitor_add(pd); - - return v; -} - static void _efl_io_model_children_list_cleanup(Eo *o EINA_UNUSED, void *data, const Eina_Future *dead_future EINA_UNUSED) { @@ -787,8 +795,10 @@ _efl_io_model_efl_model_children_count_get(const Eo *obj, Efl_Io_Model_Data *pd) f = efl_io_manager_direct_ls(iom, pd->path, EINA_FALSE, (void*) obj, _efl_io_model_children_list, NULL); + //start monitoring before listing is done + //we will filter later on if we already published a file or not + _efl_io_model_efl_model_monitor_add(pd); pd->request.listing = efl_future_then(obj, f, - .success = _efl_io_model_children_list_on, .free = _efl_io_model_children_list_cleanup, .data = pd); }