fixed bug in cache handling
authorVladimir Nadvornik <nadvornik@suse.cz>
Fri, 27 Jul 2012 13:03:58 +0000 (15:03 +0200)
committerVladimir Nadvornik <nadvornik@suse.cz>
Fri, 27 Jul 2012 13:03:58 +0000 (15:03 +0200)
changed files stayed in cache, but they were reported as not found,
this caused leaks and crashes
bug introduced by change of notification function,
commit 78cde6934008f79fe498e4adc64d187b0ed47417

src/exif-common.c
src/filecache.c

index fbc4199..93a8f8c 100644 (file)
@@ -652,6 +652,7 @@ ExifData *exif_read_fd(FileData *fd)
        if (!fd || !is_readable_file(fd->path)) return NULL;
        
        if (file_cache_get(exif_cache, fd)) return fd->exif;
+       g_assert(fd->exif == NULL);
        
        /* CACHE_TYPE_XMP_METADATA file should exist only if the metadata are
         * not writable directly, thus it should contain the most up-to-date version */
index 4d9710f..46f083d 100644 (file)
@@ -32,6 +32,7 @@ struct _FileCacheEntry {
 };
 
 static void file_cache_notify_cb(FileData *fd, NotifyType type, gpointer data);
+static void file_cache_remove_fd(FileCacheData *fc, FileData *fd);
 
 FileCacheData *file_cache_new(FileCacheReleaseFunc release, gulong max_size)
 {
@@ -67,9 +68,11 @@ gboolean file_cache_get(FileCacheData *fc, FileData *fd)
                        fc->list = g_list_remove_link(fc->list, work);
                        fc->list = g_list_concat(work, fc->list);
                        
-                       if (file_data_check_changed_files(fd)) /* this will eventually remove changed files from cache via file_cache_notify_cb */
+                       if (file_data_check_changed_files(fd)) {
+                               /* file has been changed, cance entry is no longer valid */
+                               file_cache_remove_fd(fc, fd); 
                                return FALSE;
-                               
+                       }
                        if (debug_file_cache) file_cache_dump(fc);
                        return TRUE;
                        }