[blam] Make item saving atomic



commit 19acadcff3f0f23919a922ab3a6001e46f8d4985
Author: Carlos MartÃn Nieto <carlos cmartin tk>
Date:   Fri Apr 8 18:24:34 2011 +0200

    Make item saving atomic
    
    Signed-off-by: Carlos MartÃn Nieto <carlos cmartin tk>

 src/ItemStore.cs |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/src/ItemStore.cs b/src/ItemStore.cs
index ec6b80f..3f68051 100644
--- a/src/ItemStore.cs
+++ b/src/ItemStore.cs
@@ -12,6 +12,7 @@ namespace Imendio.Blam
         private Hashtable items;
         static ItemStore instance = null;
         static string itemfile = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE;
+        static string itemfile_tmp = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE + ".tmp";
         private object db_lock = new object();
 
         public Item Get(string id)
@@ -112,11 +113,12 @@ namespace Imendio.Blam
                 items = new Item[instance.items.Count];
                 instance.items.Values.CopyTo(items, 0);
             }
-            XmlWriter writer = XmlWriter.Create(itemfile);
+            XmlWriter writer = XmlWriter.Create(itemfile_tmp);
             SyndicationFeed sf = new SyndicationFeed(items);
             Atom10FeedFormatter fmtr = sf.GetAtom10Formatter();
             fmtr.WriteTo(writer);
             writer.Close();
+            File.Move(itemfile_tmp, itemfile);
         }
 
        private ItemStore ()



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