From c29dae34a0b8fc13a188a5a57a645368325240d4 Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Tue, 2 Apr 2019 08:50:34 -0400 Subject: [PATCH] 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 --- src/lib/eio/efl_io_model.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lib/eio/efl_io_model.c b/src/lib/eio/efl_io_model.c index f023ea7597..300dac0e21 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); }