[babl] babl: generate db in temporary file



commit 87c0239ae1655bb92e08f75d1edc0f9fe27e0437
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Feb 1 00:02:42 2017 +0100

    babl: generate db in temporary file
    
    Fixing some of - but not all race conditions shown by concurrency stress test.

 babl/babl-cache.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/babl/babl-cache.c b/babl/babl-cache.c
index 723ee50..5f7b716 100644
--- a/babl/babl-cache.c
+++ b/babl/babl-cache.c
@@ -162,7 +162,11 @@ void babl_store_db (void)
 {
   BablDb *db = babl_fish_db ();
   int i;
-  FILE *dbfile = fopen (fish_cache_path (), "w");
+  char *tmpp = calloc(8000,1);
+  FILE *dbfile;
+
+  sprintf (tmpp, "%s~", fish_cache_path ());
+  dbfile  = fopen (tmpp, "w");
   if (!dbfile)
     return;
   fprintf (dbfile, "%s\n", cache_header ());
@@ -181,6 +185,9 @@ void babl_store_db (void)
       fprintf (dbfile, "%s----\n", tmp);
   }
   fclose (dbfile);
+
+  rename (tmpp, fish_cache_path());
+  free (tmpp);
 }
 
 static int


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