Mon Aug 15 18:27:38 2005 John Ellis <johne@verizon.net>
authorJohn Ellis <johne@verizon.net>
Mon, 15 Aug 2005 22:32:57 +0000 (22:32 +0000)
committerJohn Ellis <johne@verizon.net>
Mon, 15 Aug 2005 22:32:57 +0000 (22:32 +0000)
        * cache.c: Make cache loader tolerant of unknown line values, so that
        a cache written by newer/older versions of GQview does not result in
        recreating data that is actually there.

ChangeLog
src/cache.c

index efc4568..2e76b8d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Aug 15 18:27:38 2005  John Ellis  <johne@verizon.net>
+
+       * cache.c: Make cache loader tolerant of unknown line values, so that
+       a cache written by newer/older versions of GQview does not result in
+       recreating data that is actually there.
+
 Mon Aug 15 17:13:57 2005  John Ellis  <johne@verizon.net>
 
        * collect-table.c, dupe.c, exif.c, img-view.c info.c, layout_image.c,
index 597706a..87c3c5d 100644 (file)
@@ -182,16 +182,14 @@ gint cache_sim_data_save(CacheData *cd)
  *-------------------------------------------------------------------
  */
 
-static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd)
+static gint cache_sim_read_skipline(FILE *f, int s)
 {
-       if (!f || !buf || !cd) return FALSE;
-
-       if (buf[0] != '#') return FALSE;
+       if (!f) return FALSE;
 
-       if (fseek(f, 0 - (s - 1), SEEK_CUR) == 0)
+       if (fseek(f, 0 - s, SEEK_CUR) == 0)
                {
                char b;
-               while(fread(&b, sizeof(b), 1, f) == 1)
+               while (fread(&b, sizeof(b), 1, f) == 1)
                        {
                        if (b == '\n') return TRUE;
                        }
@@ -201,6 +199,15 @@ static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd)
        return FALSE;
 }
 
+static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd)
+{
+       if (!f || !buf || !cd) return FALSE;
+
+       if (s < 1 || buf[0] != '#') return FALSE;
+
+       return cache_sim_read_skipline(f, s - 1);
+}
+
 static gint cache_sim_read_dimensions(FILE *f, char *buf, int s, CacheData *cd)
 {
        if (!f || !buf || !cd) return FALSE;
@@ -425,12 +432,14 @@ static gint cache_sim_read_similarity(FILE *f, char *buf, int s, CacheData *cd)
        return FALSE;
 }
 
+#define CACHE_LOAD_LINE_NOISE 8
+
 CacheData *cache_sim_data_load(const gchar *path)
 {
        FILE *f;
        CacheData *cd = NULL;
        char buf[32];
-       gint success = TRUE;
+       gint success = CACHE_LOAD_LINE_NOISE;
        gchar *pathl;
 
        if (!path) return NULL;
@@ -448,17 +457,17 @@ CacheData *cache_sim_data_load(const gchar *path)
            strncmp(buf, "SIMcache", 8) != 0)
                {
                if (debug) printf("%s is not a cache file\n", cd->path);
-               success = FALSE;
+               success = 0;
                }
 
-       while (success)
+       while (success > 0)
                {
                int s;
                s = fread(&buf, sizeof(char), sizeof(buf), f);
 
                if (s < 1)
                        {
-                       success = FALSE;
+                       success = 0;
                        }
                else
                        {
@@ -469,7 +478,18 @@ CacheData *cache_sim_data_load(const gchar *path)
                            !cache_sim_read_md5sum(f, buf, s, cd) &&
                            !cache_sim_read_similarity(f, buf, s, cd))
                                {
-                               success = FALSE;
+                               if (!cache_sim_read_skipline(f, s))
+                                       {
+                                       success = 0;
+                                       }
+                               else
+                                       {
+                                       success--;
+                                       }
+                               }
+                       else
+                               {
+                               success = CACHE_LOAD_LINE_NOISE;
                                }
                        }
                }