Rev 4938: Better fix for fancy_rename respecting callers file encoding. in file:///home/vila/src/bzr/bugs/472161-ftp-utf8/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jan 13 14:38:57 GMT 2010


At file:///home/vila/src/bzr/bugs/472161-ftp-utf8/

------------------------------------------------------------
revno: 4938
revision-id: v.ladeuil+lp at free.fr-20100113143857-oopfzxx5g7ai53u1
parent: v.ladeuil+lp at free.fr-20100107162712-otauyp8pfo0f9xov
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 472161-ftp-utf8
timestamp: Wed 2010-01-13 15:38:57 +0100
message:
  Better fix for fancy_rename respecting callers file encoding.
  
  * bzrlib/tests/ftp_server/pyftpdlib_based.py:
  (BzrConformingFS.fs2ftp): Force unicode paths to avoid spurious
  warnings (and make code more explicit too).
  
  * bzrlib/osutils.py:
  (fancy_rename): Don't force unicode on callers, some of them
  *requires* str objects.
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2010-01-07 14:05:12 +0000
+++ b/bzrlib/osutils.py	2010-01-13 14:38:57 +0000
@@ -205,12 +205,14 @@
     :param unlink_func: A way to delete the target file if the full rename
         succeeds
     """
-    new = safe_unicode(new)
     # sftp rename doesn't allow overwriting, so play tricks:
     base = os.path.basename(new)
     dirname = os.path.dirname(new)
-    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(),
-                                       os.getpid(), rand_chars(10))
+    # callers use different encodings for the paths so the following MUST
+    # respect that. We rely on python upcasting to unicode if new is unicode
+    # and keeping a str if not.
+    tmp_name = 'tmp.%s.%.9f.%d.%s' % (base, time.time(),
+                                      os.getpid(), rand_chars(10))
     tmp_name = pathjoin(dirname, tmp_name)
 
     # Rename the file out of the way, but keep track if it didn't exist

=== modified file 'bzrlib/tests/ftp_server/pyftpdlib_based.py'
--- a/bzrlib/tests/ftp_server/pyftpdlib_based.py	2010-01-07 14:05:12 +0000
+++ b/bzrlib/tests/ftp_server/pyftpdlib_based.py	2010-01-13 14:38:57 +0000
@@ -53,7 +53,7 @@
         return [osutils.safe_utf8(s) for s in os.listdir(path)]
 
     def fs2ftp(self, fspath):
-        p = ftpserver.AbstractedFS.fs2ftp(self, fspath)
+        p = ftpserver.AbstractedFS.fs2ftp(self, osutils.safe_unicode(fspath))
         return osutils.safe_utf8(p)
 
     def ftp2fs(self, ftppath):



More information about the bazaar-commits mailing list