844e06
--- a/gvdb/gvdb-builder.c
844e06
+++ b/gvdb/gvdb-builder.c
844e06
@@ -21,6 +21,7 @@
844e06
 #include "gvdb-format.h"
844e06
 
844e06
 #include <glib.h>
844e06
+#include <glib/gstdio.h>
844e06
 #include <fcntl.h>
844e06
 #if !defined(G_OS_WIN32) || !defined(_MSC_VER)
844e06
 #include <unistd.h>
844e06
@@ -509,13 +510,20 @@ gvdb_table_write_contents (GHashTable   *table,
844e06
   gboolean status;
844e06
   FileBuilder *fb;
844e06
   GString *str;
844e06
+  GStatBuf buf;
844e06
+  gint stat_ret;
844e06
 
844e06
   fb = file_builder_new (byteswap);
844e06
   file_builder_add_hash (fb, table, &root);
844e06
   str = file_builder_serialise (fb, root);
844e06
 
844e06
+  stat_ret = g_stat (filename, &buf;;
844e06
+
844e06
   status = g_file_set_contents (filename, str->str, str->len, error);
844e06
   g_string_free (str, TRUE);
844e06
 
844e06
+  if (stat_ret == 0)
844e06
+    g_chmod (filename, buf.st_mode);
844e06
+
844e06
   return status;
844e06
 }