eio: actually detect when file changed since last monitoring request.

NOTE: Shouldn't I stat and rebuild the notify when the file is deleted
and recreated ? Advise welcome.


SVN revision: 70879
This commit is contained in:
Cedric BAIL 2012-05-09 06:54:09 +00:00
parent 123185958e
commit 22b8a6103b
4 changed files with 24 additions and 3 deletions

View File

@ -5,3 +5,7 @@
2012-04-30 Jérôme Pinot 2012-04-30 Jérôme Pinot
* Fix build out of tree. * Fix build out of tree.
2012-05-09 Cedric Bail
* Actually test if we are really requesting to monitor the same file.

View File

@ -7,6 +7,7 @@ Additions:
Fixes: Fixes:
- build out of tree. - build out of tree.
- detect when requesting to monitor a different file with the same name.
Improvements: Improvements:

View File

@ -34,7 +34,8 @@ static pid_t _monitor_pid = -1;
static void static void
_eio_monitor_free(Eio_Monitor *monitor) _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); if (monitor->exist) eio_file_cancel(monitor->exist);
@ -262,6 +263,7 @@ EAPI Eio_Monitor *
eio_monitor_stringshared_add(const char *path) eio_monitor_stringshared_add(const char *path)
{ {
Eio_Monitor *monitor; Eio_Monitor *monitor;
struct stat st;
if (_monitor_pid == -1) return NULL; if (_monitor_pid == -1) return NULL;
@ -271,17 +273,28 @@ eio_monitor_stringshared_add(const char *path)
eio_monitor_init(); eio_monitor_init();
} }
if (stat(path, &st) != 0) return NULL;
monitor = eina_hash_find(_eio_monitors, path); monitor = eina_hash_find(_eio_monitors, path);
if (monitor) if (monitor)
{ {
EINA_REFCOUNT_REF(monitor); if (st.st_mtime != monitor->mtime)
return monitor; {
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)); monitor = malloc(sizeof (Eio_Monitor));
if (!monitor) return NULL; if (!monitor) return NULL;
monitor->mtime = st.st_mtime;
monitor->backend = NULL; // This is needed to avoid race condition monitor->backend = NULL; // This is needed to avoid race condition
monitor->path = eina_stringshare_ref(path); monitor->path = eina_stringshare_ref(path);
monitor->fallback = EINA_FALSE; monitor->fallback = EINA_FALSE;

View File

@ -411,8 +411,11 @@ struct _Eio_Monitor
EINA_REFCOUNT; EINA_REFCOUNT;
int error; int error;
time_t mtime;
Eina_Bool fallback : 1; Eina_Bool fallback : 1;
Eina_Bool rename : 1; Eina_Bool rename : 1;
Eina_Bool delete_me : 1;
}; };
/* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. */ /* Be aware that ecore_thread_run could call cancel_cb if something goes wrong. */