devtools/__init__.py
branchstable
changeset 9337 70f6b183085a
parent 9235 3eb8d65824f5
child 9340 b1e933b0e850
child 9564 e2d5b0712974
--- a/devtools/__init__.py	Wed Nov 13 12:39:30 2013 +0100
+++ b/devtools/__init__.py	Fri Oct 18 17:53:11 2013 +0200
@@ -26,6 +26,7 @@
 import pickle
 import glob
 import warnings
+import tempfile
 from hashlib import sha1 # pylint: disable=E0611
 from datetime import timedelta
 from os.path import (abspath, join, exists, split, isabs, isdir)
@@ -328,8 +329,9 @@
         # XXX we dump a dict of the config
         # This is an experimental to help config dependant setup (like BFSS) to
         # be propertly restored
-        with open(config_path, 'wb') as conf_file:
+        with tempfile.NamedTemporaryFile(dir=os.path.dirname(config_path), delete=False) as conf_file:
             conf_file.write(pickle.dumps(dict(self.config)))
+        os.rename(conf_file.name, config_path)
         self.db_cache[self.db_cache_key(db_id)] = (backup_data, config_path)
 
     def _backup_database(self, db_id):