eio: actually detect when file changed since last monitoring request.
authorCedric BAIL <cedric.bail@free.fr>
Wed, 9 May 2012 06:54:09 +0000 (06:54 +0000)
committerCedric BAIL <cedric.bail@free.fr>
Wed, 9 May 2012 06:54:09 +0000 (06:54 +0000)
NOTE: Shouldn't I stat and rebuild the notify when the file is deleted
and recreated ? Advise welcome.

SVN revision: 70879

legacy/eio/ChangeLog
legacy/eio/NEWS
legacy/eio/src/lib/eio_monitor.c
legacy/eio/src/lib/eio_private.h

index 80dbd9c..a378d13 100644 (file)
@@ -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.
index e449e56..0007dba 100644 (file)
@@ -7,6 +7,7 @@ Additions:
 
 Fixes:
        - build out of tree.
+       - detect when requesting to monitor a different file with the same name.
 
 Improvements:
 
index cc7ce1d..ec3c9f5 100644 (file)
@@ -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;
index d0f9367..0802aba 100644 (file)
@@ -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. */