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