store cache->mode, error handling for pt_image_update_cache
authorTero Marttila <terom@fixme.fi>
Mon, 28 Dec 2009 19:58:51 +0200
changeset 3 da7c6dcafb43
parent 2 05de54150a4c
child 4 49362b34116c
store cache->mode, error handling for pt_image_update_cache
src/lib/cache.c
src/lib/image.c
--- a/src/lib/cache.c	Mon Dec 28 19:54:41 2009 +0200
+++ b/src/lib/cache.c	Mon Dec 28 19:58:51 2009 +0200
@@ -10,7 +10,7 @@
 
 
 
-static int pt_cache_new (struct pt_cache **cache_ptr, const char *path)
+static int pt_cache_new (struct pt_cache **cache_ptr, const char *path, int mode)
 {
     struct pt_cache *cache;
 
@@ -23,6 +23,7 @@
 
     // init
     cache->fd = -1;
+    cache->mode = mode;
 
     // ok
     *cache_ptr = cache;
@@ -42,7 +43,7 @@
     struct pt_cache *cache;
     
     // alloc
-    if (pt_cache_new(&cache, path))
+    if (pt_cache_new(&cache, path, mode))
         return -1;
     
     // ok
--- a/src/lib/image.c	Mon Dec 28 19:54:41 2009 +0200
+++ b/src/lib/image.c	Mon Dec 28 19:58:51 2009 +0200
@@ -175,14 +175,17 @@
     if (pt_cache_open(&image->cache, cache_path, cache_mode))
         goto error;
     
-    // update if not fresh
+    // compare cache with image
     // XXX: check cache_mode
     if ((stale = pt_cache_stale(image->cache, image->path)) < 0)
         goto error;
 
-    if (stale)
-        pt_image_update_cache(image);
-    
+    // update if not fresh
+    if (stale) {
+        if (pt_image_update_cache(image))
+            goto error;
+    }
+
     // ok, ready for access
     *image_ptr = image;