Blob Blame Raw
From 6592ecb3b95146b84072cf276eb98fba324b11ad Mon Sep 17 00:00:00 2001
From: Christian Kellner <gicmo@gnome.org>
Date: Wed, 18 Nov 2009 14:33:36 +0000
Subject: Fsync the directory when rotating the metadata

This is needed so we never end up having a stable file with the
rotated bit set. Should fix bug #600057.
---
diff --git a/metadata/metabuilder.c b/metadata/metabuilder.c
index a4a2043..bffdd16 100644
--- a/metadata/metabuilder.c
+++ b/metadata/metabuilder.c
@@ -1010,8 +1010,8 @@ meta_builder_write (MetaBuilder *builder,
 {
   GString *out;
   guint32 random_tag;
-  int fd, fd2;
-  char *tmp_name;
+  int fd, fd2, fd_dir;
+  char *tmp_name, *dirname;
 
   out = metadata_create_static (builder, &random_tag);
 
@@ -1035,6 +1035,17 @@ meta_builder_write (MetaBuilder *builder,
       goto out;
     }
 
+  /* Sync the directory to make sure that the entry in the directory containing
+     the new medata file has also reached disk. */
+  dirname = g_path_get_dirname (filename);
+  fd_dir = open (dirname, O_RDONLY);
+  if (fd_dir > -1)
+    {
+      fsync (fd_dir);
+      close (fd_dir);
+    }
+  g_free (dirname);
+
   /* Mark old file (if any) as rotated) */
   if (fd2 != -1)
     {
--
cgit v0.8.2