gio-querymodules: unlink instead of writing empty cache
authorRyan Lortie <desrt@desrt.ca>
Thu, 8 Mar 2012 16:55:09 +0000 (11:55 -0500)
committerRyan Lortie <desrt@desrt.ca>
Thu, 8 Mar 2012 17:07:03 +0000 (12:07 -0500)
If there are no modules installed then the most appropriate thing is to
have no cachefile instead of an empty one.  This unbreaks the "clean
directory after 'make uninstall'" check that automake does.

https://bugzilla.gnome.org/show_bug.cgi?id=671664

gio/gio-querymodules.c

index 716a7b8..0ebc850 100644 (file)
@@ -23,6 +23,9 @@
 #include "config.h"
 #include "giomodule.h"
 
+#include <gstdio.h>
+#include <errno.h>
+
 static gboolean
 is_valid_module_name (const gchar *basename)
 {
@@ -101,11 +104,20 @@ query_dir (const char *dirname)
 
   cachename = g_build_filename (dirname, "giomodule.cache", NULL);
 
-  error = NULL;
-  if (!g_file_set_contents (cachename, data->str, data->len, &error))
+  if (data->len > 0)
     {
-      g_printerr ("Unable to create %s: %s\n", cachename, error->message);
-      g_error_free (error);
+      error = NULL;
+
+      if (!g_file_set_contents (cachename, data->str, data->len, &error))
+        {
+          g_printerr ("Unable to create %s: %s\n", cachename, error->message);
+          g_error_free (error);
+        }
+    }
+  else
+    {
+      if (g_unlink (cachename) != 0 && errno != ENOENT)
+        g_printerr ("Unable to unlink %s: %s\n", cachename, g_strerror (errno));
     }
 
   g_string_free (data, TRUE);