[Xfce4-commits] <midori:master> Adblock: use fs modification time to prevent unneded downloads

Christian Dywan noreply at xfce.org
Tue Sep 11 00:46:05 CEST 2012


Updating branch refs/heads/master
         to f29318af7ce6e65599fb3509b36e1a665ddcb3a0 (commit)
       from 9af985e7e8507709efef941b84225b90b6407880 (commit)

commit f29318af7ce6e65599fb3509b36e1a665ddcb3a0
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Fri Sep 7 19:59:37 2012 +0200

    Adblock: use fs modification time to prevent unneded downloads

 extensions/adblock.c |   53 +++++++++++++++++++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 78bf6cf..5ed3258 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -1568,6 +1568,7 @@ adblock_file_is_up_to_date (gchar* path)
         gchar* timestamp = NULL;
         guint i;
         gboolean found_meta = FALSE;
+        gint fs_days_elapsed, days_elapsed = 0, least_days;
 
         for (i = 0; i <= 10; i++)
         {
@@ -1609,10 +1610,32 @@ adblock_file_is_up_to_date (gchar* path)
             return FALSE;
         }
 
-        if (days_to_expire && timestamp != NULL)
+        /* query filesystem about file change, maybe there is no update yet
+         * or there is no "modified" metadata to check, otherwise we will repeatedly
+         * download files that have no new updates */
         {
-            gint days_elapsed = 0;
+            GDate* current = g_date_new ();
+            GDate* fs_mod_date = g_date_new ();
+            GTimeVal mod_time;
+            GFile* filter_file = g_file_new_for_path (path);
+            GFileInfo* info = g_file_query_info (filter_file, "time:modified", 0, NULL, NULL);
+
+            g_file_info_get_modification_time (info, &mod_time);
+            g_date_set_time_t (current, time (NULL));
+            g_date_set_time_val (fs_mod_date, &mod_time);
+
+            fs_days_elapsed = g_date_days_between (fs_mod_date, current);
+
+            g_date_free (current);
+            g_date_free (fs_mod_date);
+        }
+
+        /* If there is no update metadata but file is valid, assume one week */
+        if ((!days_to_expire && !timestamp) && fs_days_elapsed < 7)
+            return TRUE;
 
+        if (days_to_expire && timestamp != NULL)
+        {
             GDate* current = g_date_new ();
             GDate* mod_date = g_date_new ();
             gchar** parts;
@@ -1643,22 +1666,22 @@ adblock_file_is_up_to_date (gchar* path)
             g_date_free (current);
             g_date_free (mod_date);
             g_free (timestamp);
+        }
 
-            /* File from the future? Assume up to date, not to loop */
-            if (days_elapsed < 0)
-            {
-                g_print ("Adblock: file %s appears to be from the future,"
-                         "check your system clock!\n", path);
-                return TRUE;
-            }
-
-            if (days_elapsed < days_to_expire)
-                return TRUE;
-            else
-                return FALSE;
+        /* File from the future? Assume up to date */
+        if (days_elapsed < 0)
+        {
+            g_print ("Adblock: file %s appears to be from the future,"
+                     "check your system clock!\n", path);
+            return TRUE;
         }
+
+        least_days = days_elapsed < fs_days_elapsed ? days_elapsed : fs_days_elapsed;
+        if (least_days < days_to_expire)
+            return TRUE;
         else
-            g_free (timestamp);
+            return FALSE;
+
         return TRUE;
     }
     return FALSE;


More information about the Xfce4-commits mailing list