summaryrefslogtreecommitdiff
path: root/src/gallery-utils.c
diff options
context:
space:
mode:
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);
+}