Rev 4848: (vila) Minimal fix for bug #525571 to ease backport to launchpad. (Vincent in file:///home/pqm/archives/thelove/bzr/2.1/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jul 2 17:21:24 BST 2010


At file:///home/pqm/archives/thelove/bzr/2.1/

------------------------------------------------------------
revno: 4848 [merge]
revision-id: pqm at pqm.ubuntu.com-20100702162122-nh3z4l1omh7h0li3
parent: pqm at pqm.ubuntu.com-20100616143824-gf3fau7lsk1st9zp
parent: v.ladeuil+lp at free.fr-20100702143906-se1tm1vtvz8y47fp
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.1
timestamp: Fri 2010-07-02 17:21:22 +0100
message:
  (vila) Minimal fix for bug #525571 to ease backport to launchpad. (Vincent
   Ladeuil)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
=== 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 14:39:06 +0000
@@ -74,6 +74,7 @@
 
 import bzrlib
 from bzrlib import (
+    atomicfile,
     debug,
     errors,
     mail_client,
@@ -510,9 +511,12 @@
         self._write_config_file()
 
     def _write_config_file(self):
-        f = open(self._get_filename(), 'wb')
+        f = StringIO()
         self._get_parser().write(f)
-        f.close()
+        atomic_file = atomicfile.AtomicFile(self._get_filename())
+        atomic_file.write(f.getvalue())
+        atomic_file.commit()
+        atomic_file.close()
 
 
 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'))
+        f = StringIO()
+        self._get_parser().write(f)
+        atomic_file = atomicfile.AtomicFile(self._get_filename())
+        atomic_file.write(f.getvalue())
+        atomic_file.commit()
+        atomic_file.close()
 
 
 class BranchConfig(Config):




More information about the bazaar-commits mailing list