diff --git a/legacy/eio/ChangeLog b/legacy/eio/ChangeLog index 80dbd9c59f..a378d13c36 100644 --- a/legacy/eio/ChangeLog +++ b/legacy/eio/ChangeLog @@ -5,3 +5,7 @@ 2012-04-30 Jérôme Pinot * Fix build out of tree. + +2012-05-09 Cedric Bail + + * Actually test if we are really requesting to monitor the same file. diff --git a/legacy/eio/NEWS b/legacy/eio/NEWS index e449e56a9c..0007dba58c 100644 --- a/legacy/eio/NEWS +++ b/legacy/eio/NEWS @@ -7,6 +7,7 @@ Additions: Fixes: - build out of tree. + - detect when requesting to monitor a different file with the same name. Improvements: diff --git a/legacy/eio/src/lib/eio_monitor.c b/legacy/eio/src/lib/eio_monitor.c index cc7ce1d0a7..ec3c9f54a4 100644 --- a/legacy/eio/src/lib/eio_monitor.c +++ b/legacy/eio/src/lib/eio_monitor.c @@ -34,7 +34,8 @@ static pid_t _monitor_pid = -1; static void _eio_monitor_free(Eio_Monitor *monitor) { - eina_hash_del(_eio_monitors, monitor->path, monitor); + if (!monitor->delete_me) + eina_hash_del(_eio_monitors, monitor->path, monitor); if (monitor->exist) eio_file_cancel(monitor->exist); @@ -262,6 +263,7 @@ EAPI Eio_Monitor * eio_monitor_stringshared_add(const char *path) { Eio_Monitor *monitor; + struct stat st; if (_monitor_pid == -1) return NULL; @@ -271,17 +273,28 @@ eio_monitor_stringshared_add(const char *path) eio_monitor_init(); } + if (stat(path, &st) != 0) return NULL; + monitor = eina_hash_find(_eio_monitors, path); if (monitor) { - EINA_REFCOUNT_REF(monitor); - return monitor; + if (st.st_mtime != monitor->mtime) + { + monitor->delete_me = EINA_TRUE; + eina_hash_del(_eio_monitors, monitor->path, monitor); + } + else + { + EINA_REFCOUNT_REF(monitor); + return monitor; + } } monitor = malloc(sizeof (Eio_Monitor)); if (!monitor) return NULL; + monitor->mtime = st.st_mtime; monitor->backend = NULL; // This is needed to avoid race condition monitor->path = eina_stringshare_ref(path); monitor->fallback = EINA_FALSE; diff --git a/legacy/eio/src/lib/eio_private.h b/legacy/eio/src/lib/eio_private.h index d0f9367bd5..0802aba2df 100644 --- a/legacy/eio/src/lib/eio_private.h +++ b/legacy/eio/src/lib/eio_private.h @@ -411,8 +411,11 @@ struct _Eio_Monitor EINA_REFCOUNT; int error; + time_t mtime; + Eina_Bool fallback : 1; Eina_Bool rename : 1; + Eina_Bool delete_me : 1; }; /* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. */