# HG changeset patch # User Tero Marttila # Date 1262034918 -7200 # Node ID 400ddf1e7aa959ea5b0e8ad2b01fdfc53326e027 # Parent 997906f5fd2d1bcf2ebce67e1544da3a114f84fc pt_image_status diff -r 997906f5fd2d -r 400ddf1e7aa9 src/lib/cache.c --- a/src/lib/cache.c Mon Dec 28 22:50:00 2009 +0200 +++ b/src/lib/cache.c Mon Dec 28 23:15:18 2009 +0200 @@ -55,7 +55,7 @@ return 0; } -int pt_cache_stale (struct pt_cache *cache, const char *img_path) +int pt_cache_status (struct pt_cache *cache, const char *img_path) { struct stat st_img, st_cache; @@ -67,13 +67,17 @@ if (stat(cache->path, &st_cache) < 0) { // always stale if it doesn't exist yet if (errno == ENOENT) - return 1; + return PT_CACHE_NONE; else return -1; } // compare mtime - return (st_img.st_mtime > st_cache.st_mtime); + if (st_img.st_mtime > st_cache.st_mtime) + return PT_CACHE_STALE; + + else + return PT_CACHE_FRESH; } /** diff -r 997906f5fd2d -r 400ddf1e7aa9 src/lib/cache.h --- a/src/lib/cache.h Mon Dec 28 22:50:00 2009 +0200 +++ b/src/lib/cache.h Mon Dec 28 23:15:18 2009 +0200 @@ -67,9 +67,11 @@ int pt_cache_open (struct pt_cache **cache_ptr, const char *path, int mode); /** - * Verify if the cached data has become stale compared to the given original file. + * Verify if the cached data eixsts, or has become stale compared to the given original file. + * + * @return one of pt_cache_status; <0 on error, 0 if fresh, >0 otherwise */ -int pt_cache_stale (struct pt_cache *cache, const char *img_path); +int pt_cache_status (struct pt_cache *cache, const char *img_path); /** * Update the cache data from the given PNG image. diff -r 997906f5fd2d -r 400ddf1e7aa9 src/lib/image.c --- a/src/lib/image.c Mon Dec 28 22:50:00 2009 +0200 +++ b/src/lib/image.c Mon Dec 28 23:15:18 2009 +0200 @@ -203,9 +203,9 @@ return 0; } -int pt_image_stale (struct pt_image *image) +int pt_image_status (struct pt_image *image) { - return pt_cache_stale(image->cache, image->path); + return pt_cache_status(image->cache, image->path); } int pt_image_update (struct pt_image *image) diff -r 997906f5fd2d -r 400ddf1e7aa9 src/lib/pngtile.h --- a/src/lib/pngtile.h Mon Dec 28 22:50:00 2009 +0200 +++ b/src/lib/pngtile.h Mon Dec 28 23:15:18 2009 +0200 @@ -27,6 +27,23 @@ PT_IMG_STALE = 0x02, }; +/** + * Values for pt_image_cached + */ +enum pt_cache_status { + /** Cache status could not be determined */ + PT_CACHE_ERROR = -1, + + /** Cache is fresh */ + PT_CACHE_FRESH = 0, + + /** Cache does not exist */ + PT_CACHE_NONE = 1, + + /** Cache exists, but is stale */ + PT_CACHE_STALE = 2, +}; + /** Metadata info for image */ struct pt_image_info { /** Dimensions of image */ @@ -52,9 +69,11 @@ int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr); /** - * Check the given image's cache is stale - in other words, the image needs to be updated. + * Check the given image's cache is stale - in other words, if the image needs to be update()'d. + * + * @return one of pt_cache_status */ -int pt_image_stale (struct pt_image *image); +int pt_image_status (struct pt_image *image); /** * Update the given image's cache. diff -r 997906f5fd2d -r 400ddf1e7aa9 src/util/main.c --- a/src/util/main.c Mon Dec 28 22:50:00 2009 +0200 +++ b/src/util/main.c Mon Dec 28 23:15:18 2009 +0200 @@ -87,7 +87,7 @@ struct pt_ctx *ctx = NULL; struct pt_image *image = NULL; - int stale; + enum pt_cache_status status; log_debug("Processing %d images...", argc - optind); @@ -105,17 +105,23 @@ log_info("Opened image at: %s", img_path); // check if stale - if ((stale = pt_image_stale(image)) < 0) { - log_errno("pt_image_stale: %s", img_path); + if ((status = pt_image_status(image)) < 0) { + log_errno("pt_image_status: %s", img_path); goto error; } // update if stale - if (stale || force_update) { - if (stale) - log_debug("Image cache is stale, updating..."); - else // force_update - log_debug("Updating image cache..."); + if (status != PT_CACHE_FRESH || force_update) { + if (status == PT_CACHE_NONE) + log_debug("Image cache is missing"); + + else if (status == PT_CACHE_STALE) + log_debug("Image cache is stale"); + + else if (status == PT_CACHE_FRESH) + log_debug("Image cache is fresh"); + + log_debug("Updating image cache..."); if (pt_image_update(image)) { log_warn_errno("pt_image_update: %s", img_path);