From 29a04be6c9cbaf0865c8b57428b7b7c37fbda4c3 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 27 Jun 2014 18:25:57 +0200
Subject: [PATCH 14/14] Add "-n" option to update-mime-database

When "-n" is passed, the cache will only be updated if
$MIME_DIR/packages or one of the files in that directory is newer
than $MIME_DIR/version.

This is useful for package pre- and post-installation scripts.
---
 update-mime-database.1 |  7 +++++++
 update-mime-database.c | 10 +++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/update-mime-database.1 b/update-mime-database.1
index c9164e1..b18eac3 100644
--- update-mime-database.1
+++ update-mime-database.1
@@ -16,6 +16,8 @@ update-mime-database \- a program to build the Shared MIME-Info database cache
 .B \-v
 | [
 .B \-V
+|
+.B \-n
 ]
 .I MIME-DIR
 
@@ -38,6 +40,11 @@ Print out the version information.
 .TP
 \fB\-V\fR
 Be verbose.
+.TP
+\fB\-n\fR
+Only update if \fBMIME-DIR\fR/packages/ or a file in that directory
+is newer than \fBMIME-DIR\fR/version. This is useful for package pre-
+and post-installation scripts.
 
 .SH ARGUMENTS
 .TP
diff --git a/update-mime-database.c b/update-mime-database.c
index d1849a3..be4aba2 100644
--- update-mime-database.c
+++ update-mime-database.c
@@ -194,7 +194,7 @@ fatal_gerror (GError *error)
 
 static void usage(const char *name)
 {
-	g_fprintf(stderr, _("Usage: %s [-hvV] MIME-DIR\n"), name);
+	g_fprintf(stderr, _("Usage: %s [-hvVn] MIME-DIR\n"), name);
 }
 
 static void free_type(gpointer data)
@@ -3601,11 +3601,12 @@ int main(int argc, char **argv)
 	int opt;
 	GError *local_error = NULL;
 	GError **error = &local_error;
+	gboolean if_newer = FALSE;
 
 	/* Install the filtering log handler */
 	g_log_set_default_handler(g_log_handler, NULL);
 
-	while ((opt = getopt(argc, argv, "hvV")) != -1)
+	while ((opt = getopt(argc, argv, "hvVn")) != -1)
 	{
 		switch (opt)
 		{
@@ -3624,6 +3625,9 @@ int main(int argc, char **argv)
 				enabled_log_levels |= G_LOG_LEVEL_MESSAGE
 						      | G_LOG_LEVEL_INFO;
 				break;
+			case 'n':
+				if_newer = TRUE;
+				break;
 			default:
 				return EXIT_FAILURE;
 		}
@@ -3666,7 +3670,7 @@ int main(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	if (is_cache_up_to_date(mime_dir, package_dir)) {
+	if (if_newer && is_cache_up_to_date(mime_dir, package_dir)) {
 		g_message ("Skipping mime update as the cache is up-to-date");
 		return EXIT_SUCCESS;
 	}
-- 
1.9.3

