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