# HG changeset patch # User Tero Marttila # Date 1264367830 -7200 # Node ID 4a25113cb2a4b8a1581b3a2cef3c1004c37b7b21 # Parent 8a3165c604f8738e25b76df1c5d33e562d4efccb add some additional pt_image_info fields for stat diff -r 8a3165c604f8 -r 4a25113cb2a4 include/pngtile.h --- a/include/pngtile.h Sun Jan 24 23:04:55 2010 +0200 +++ b/include/pngtile.h Sun Jan 24 23:17:10 2010 +0200 @@ -9,6 +9,7 @@ #include #include // for FILE* #include +#include // for time_t /** * "Global" context shared between images @@ -46,18 +47,24 @@ PT_CACHE_STALE = 2, }; -/** Metadata info for image */ +/** Metadata info for image. Values will be set to zero if not available */ struct pt_image_info { /** Dimensions of image */ size_t width, height; + /** Last update of image file */ + time_t image_mtime; + /** Size of image file in bytes */ size_t image_bytes; + /** Last update of cache file */ + time_t cache_mtime; + /** Size of cache file in bytes */ size_t cache_bytes; - /** Size of cache file in blocks (for sparse cache files) */ + /** Size of cache file in blocks (for sparse cache files) - 512 bytes / block? */ size_t cache_blocks; }; diff -r 8a3165c604f8 -r 4a25113cb2a4 src/lib/cache.c --- a/src/lib/cache.c Sun Jan 24 23:04:55 2010 +0200 +++ b/src/lib/cache.c Sun Jan 24 23:17:10 2010 +0200 @@ -69,6 +69,7 @@ int pt_cache_info (struct pt_cache *cache, struct pt_image_info *info) { + struct stat st; int err; // ensure open @@ -78,6 +79,20 @@ info->width = cache->header->width; info->height = cache->header->height; + // stat + if (stat(cache->path, &st) < 0) { + // unknown + info->cache_mtime = 0; + info->cache_bytes = 0; + info->cache_blocks = 0; + + } else { + // store + info->cache_mtime = st.st_mtime; + info->cache_bytes = st.st_size; + info->cache_blocks = st.st_blocks; + } + return 0; } diff -r 8a3165c604f8 -r 4a25113cb2a4 src/lib/image.c --- a/src/lib/image.c Sun Jan 24 23:04:55 2010 +0200 +++ b/src/lib/image.c Sun Jan 24 23:17:10 2010 +0200 @@ -7,6 +7,8 @@ #include "shared/log.h" #include +#include +#include #include #include @@ -204,11 +206,24 @@ int pt_image_info (struct pt_image *image, const struct pt_image_info **info_ptr) { + struct stat st; int err; // update info if ((err = pt_cache_info(image->cache, &image->info))) return err; + + // stat our info + if (stat(image->path, &st) < 0) { + // unknown + image->info.image_mtime = 0; + image->info.image_bytes = 0; + + } else { + // store + image->info.image_mtime = st.st_mtime; + image->info.image_bytes = st.st_size; + } // return pointer *info_ptr = &image->info; diff -r 8a3165c604f8 -r 4a25113cb2a4 src/util/main.c --- a/src/util/main.c Sun Jan 24 23:04:55 2010 +0200 +++ b/src/util/main.c Sun Jan 24 23:17:10 2010 +0200 @@ -201,11 +201,16 @@ // show info const struct pt_image_info *img_info; - if ((err = pt_image_info(image, &img_info))) + if ((err = pt_image_info(image, &img_info))) { log_warn_errno("pt_image_info: %s: %s", img_path, pt_strerror(err)); - else + } else { log_info("\tImage dimensions: %zux%zu", img_info->width, img_info->height); + log_info("\tImage mtime=%u, bytes=%zu", img_info->image_mtime, img_info->image_bytes); + log_info("\tCache mtime=%u, bytes=%zu, blocks=%zu (%zu bytes)", + img_info->cache_mtime, img_info->cache_bytes, img_info->cache_blocks, img_info->cache_blocks * 512, + ); + } // render tile? if (ti.width && ti.height) {