[gvfs] Fsync the directory when rotating the metadata



commit 6592ecb3b95146b84072cf276eb98fba324b11ad
Author: Christian Kellner <gicmo gnome org>
Date:   Wed Nov 18 15:33:36 2009 +0100

    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.

 metadata/metabuilder.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
---
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)
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]