Rev 4848: Minimal fix to avoid overriding writes for config files. in file:///home/vila/src/bzr/bugs/525571-minimal-lock-bazaar-conf-files/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Jul 2 14:55:21 BST 2010


At file:///home/vila/src/bzr/bugs/525571-minimal-lock-bazaar-conf-files/

------------------------------------------------------------
revno: 4848
revision-id: v.ladeuil+lp at free.fr-20100702135521-aem1nvft10ck1634
parent: pqm at pqm.ubuntu.com-20100616143824-gf3fau7lsk1st9zp
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 525571-minimal-lock-bazaar-conf-files
timestamp: Fri 2010-07-02 15:55:21 +0200
message:
  Minimal fix to avoid overriding writes for config files.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2010-06-16 12:12:56 +0000
+++ b/NEWS	2010-07-02 13:55:21 +0000
@@ -20,6 +20,10 @@
 Bug Fixes
 *********
 
+* Configuration files in ``${BZR_HOME}`` are now written in an atomic
+  way which should help avoid problems with concurrent writers.
+  (Vincent Ladeuil, #525571)
+
 * Raise ValueError instead of a string exception.
   (John Arbash Meinel, #586926)
 

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/config.py	2010-07-02 13:55:21 +0000
@@ -81,6 +81,7 @@
     registry,
     symbol_versioning,
     trace,
+    transport,
     ui,
     urlutils,
     win32utils,
@@ -510,9 +511,12 @@
         self._write_config_file()
 
     def _write_config_file(self):
-        f = open(self._get_filename(), 'wb')
+        fname = osutils.safe_unicode(self._get_filename())
+        conf_dir = os.path.dirname(fname)
+        t = transport.get_transport(conf_dir)
+        f = StringIO()
         self._get_parser().write(f)
-        f.close()
+        t.put_bytes(os.path.basename(fname), f.getvalue())
 
 
 class LocationConfig(IniBasedConfig):
@@ -653,7 +657,12 @@
         self._get_parser()[location][option]=value
         # the allowed values of store match the config policies
         self._set_option_policy(location, option, store)
-        self._get_parser().write(file(self._get_filename(), 'wb'))
+        fname = osutils.safe_unicode(self._get_filename())
+        conf_dir = os.path.dirname(fname)
+        t = transport.get_transport(conf_dir)
+        f = StringIO()
+        self._get_parser().write(f)
+        t.put_bytes(os.path.basename(fname), f.getvalue())
 
 
 class BranchConfig(Config):



More information about the bazaar-commits mailing list