Rev 4849: Use AtomicFile and avoid all unicode/encoding issues around transport (thanks jam). in file:///home/vila/src/bzr/bugs/525571-minimal-lock-bazaar-conf-files/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Jul 2 15:39:06 BST 2010


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

------------------------------------------------------------
revno: 4849
revision-id: v.ladeuil+lp at free.fr-20100702143906-se1tm1vtvz8y47fp
parent: v.ladeuil+lp at free.fr-20100702135521-aem1nvft10ck1634
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 525571-minimal-lock-bazaar-conf-files
timestamp: Fri 2010-07-02 16:39:06 +0200
message:
  Use AtomicFile and avoid all unicode/encoding issues around transport (thanks jam).
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2010-07-02 13:55:21 +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,
@@ -81,7 +82,6 @@
     registry,
     symbol_versioning,
     trace,
-    transport,
     ui,
     urlutils,
     win32utils,
@@ -511,12 +511,12 @@
         self._write_config_file()
 
     def _write_config_file(self):
-        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())
+        atomic_file = atomicfile.AtomicFile(self._get_filename())
+        atomic_file.write(f.getvalue())
+        atomic_file.commit()
+        atomic_file.close()
 
 
 class LocationConfig(IniBasedConfig):
@@ -657,12 +657,12 @@
         self._get_parser()[location][option]=value
         # the allowed values of store match the config policies
         self._set_option_policy(location, option, store)
-        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())
+        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