From a36f51c503e2989889692cda72223874eb573d89 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Wed, 14 Aug 2013 05:44:05 +0000 Subject: [PATCH] Add timestamp checking --- gallery/gallery.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gallery/gallery.c b/gallery/gallery.c index 5b727dc..df9a37d 100644 --- a/gallery/gallery.c +++ b/gallery/gallery.c @@ -5,10 +5,15 @@ void resize(gchar *orig, gchar *thumb, gchar *size) { - gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL}; - /* god damn glib */ - g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL, NULL, NULL); + GStatBuf oinfo, tinfo; + int oval = g_stat(orig, &oinfo); + int tval = g_stat(thumb, &tinfo); + if (tval || (!oval && oinfo.st_mtime > tinfo.st_mtime)) { + /* god damn glib */ + gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL}; + g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, + NULL, NULL, NULL, NULL, NULL, NULL); + } } GList *gen_thumbs(GList *images) @@ -21,10 +26,8 @@ GList *gen_thumbs(GList *images) gchar *large = g_build_filename("large", name, NULL); gchar *small = g_build_filename("small", name, NULL); gchar *thumb = g_build_filename("thumb", name, NULL); - if (!g_file_test(thumb, G_FILE_TEST_EXISTS)) { - resize(large, thumb, "200x200"); - resize(large, small, "800x800"); - } + resize(large, thumb, "200x200"); + resize(large, small, "800x800"); g_free(large); g_free(small); g_free(thumb); -- 2.43.2