summaryrefslogtreecommitdiff
path: root/src/gallery-utils.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-04-25 15:39:55 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-04-25 15:39:55 +0200
commit40334d2dec0545100edcca403d50ad6b1b015a9a (patch)
tree70e76683eec8b4036d23f2253ea65ddb06d7c8dd /src/gallery-utils.c
parent54f18873efeef6e0ae4ac8cb46c15d0a1bee37f5 (diff)
downloadcataract-40334d2dec0545100edcca403d50ad6b1b015a9a.tar.xz
Update mode
By doing update, cgg will check the output structure for missing files and re-generate them as necessary. The decision whether an item (file, picture, album) needs to be updated is done by comparing timestamps (mtime specifically). Due to that reason it's important to keep this fact in mind when replacing single image which carries older timestamp than other files. Either don't use the update mode or 'touch' that new file. Changes made to any XML file will result in whole album re-generation (excluding subalbums).
Diffstat (limited to 'src/gallery-utils.c')
-rw-r--r--src/gallery-utils.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gallery-utils.c b/src/gallery-utils.c
index 8ec258a..29c456d 100644
--- a/src/gallery-utils.c
+++ b/src/gallery-utils.c
@@ -326,3 +326,32 @@ log_error (const gchar *format, ...)
stats_errors_inc ();
}
+
+
+/*
+ * needs_update: returns TRUE if the destionation file needs updating, also when missing
+ */
+gboolean
+needs_update (const char *source, const char *dest)
+{
+ struct stat src_stat;
+ struct stat dst_stat;
+
+ memset (&src_stat, 0, sizeof (src_stat));
+ memset (&dst_stat, 0, sizeof (dst_stat));
+
+ /* if we can't stat the source file, return FALSE to prevent further errors during update */
+ if (stat (source, &src_stat) == -1) {
+ log_error ("needs_update: cannot stat source file \"%s\": %s\n", source, strerror (errno));
+ return FALSE;
+ }
+
+ /* if we can't stat the destination file, we need update anyway */
+ if (stat (dest, &dst_stat) == -1)
+ return TRUE;
+ /* destination file size should not be zero */
+ if (dst_stat.st_size <= 0)
+ return TRUE;
+
+ return (src_stat.st_mtime > dst_stat.st_mtime);
+}