Adblock: check if file contains any metadata first

This commit is contained in:
Paweł Forysiuk 2012-09-05 23:58:21 +02:00 committed by Christian Dywan
parent 8de05bc07d
commit 82242a8c2e
1 changed files with 13 additions and 2 deletions

View File

@ -1539,14 +1539,16 @@ static gboolean
adblock_file_is_up_to_date (gchar* path) adblock_file_is_up_to_date (gchar* path)
{ {
FILE* file; FILE* file;
guint days_to_expire = 0;
gchar* timestamp = NULL;
gchar line[2000]; gchar line[2000];
/* Check a chunk of header for update info */ /* Check a chunk of header for update info */
if ((file = g_fopen (path, "r"))) if ((file = g_fopen (path, "r")))
{ {
guint days_to_expire = 0;
gchar* timestamp = NULL;
guint i; guint i;
gboolean found_meta = FALSE;
for (i = 0; i <= 10; i++) for (i = 0; i <= 10; i++)
{ {
fgets (line, 2000, file); fgets (line, 2000, file);
@ -1555,6 +1557,7 @@ adblock_file_is_up_to_date (gchar* path)
gchar** parts = g_strsplit (line, " ", 4); gchar** parts = g_strsplit (line, " ", 4);
days_to_expire = atoi (parts[2]); days_to_expire = atoi (parts[2]);
g_strfreev (parts); g_strfreev (parts);
found_meta = TRUE;
} }
if (strncmp ("! This list expires after", line, 25) == 0) if (strncmp ("! This list expires after", line, 25) == 0)
{ {
@ -1566,6 +1569,7 @@ adblock_file_is_up_to_date (gchar* path)
days_to_expire = (atoi (parts[5])) / 24; days_to_expire = (atoi (parts[5])) / 24;
g_strfreev (parts); g_strfreev (parts);
found_meta = TRUE;
} }
if (strncmp ("! Last modified", line, 15) == 0 if (strncmp ("! Last modified", line, 15) == 0
@ -1575,9 +1579,16 @@ adblock_file_is_up_to_date (gchar* path)
timestamp = g_strdup (parts[1] + 1); timestamp = g_strdup (parts[1] + 1);
g_strchomp (timestamp); g_strchomp (timestamp);
g_strfreev (parts); g_strfreev (parts);
found_meta = TRUE;
} }
} }
if (!found_meta)
{
g_print ("Adblock: no metadata found in %s (broken download?)\n", path);
return FALSE;
}
if (days_to_expire && timestamp != NULL) if (days_to_expire && timestamp != NULL)
{ {
guint days_elapsed = 0; guint days_elapsed = 0;