Rev 5156: (lifeless) File system encode names given to tarfile in export, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Apr 14 13:31:08 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5156 [merge]
revision-id: pqm at pqm.ubuntu.com-20100414123101-k7ty3rl98pyv099l
parent: pqm at pqm.ubuntu.com-20100414111428-ujyymfxw5zn3klcf
parent: parth.malwankar at gmail.com-20100414101222-uiu2ucurptoz1dg1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-04-14 13:31:01 +0100
message:
  (lifeless) File system encode names given to tarfile in export,
   to workaround a posixpath.py issue in Python < 2.6.5. (Parth Malwankar)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/export/tar_exporter.py  tar_exporter.py-20051114235828-1f6349a2f090a5d0
  bzrlib/tests/blackbox/test_export.py test_export.py-20051229024010-e6c26658e460fb1c
=== modified file 'NEWS'
--- a/NEWS	2010-04-14 11:14:28 +0000
+++ b/NEWS	2010-04-14 12:31:01 +0000
@@ -28,6 +28,11 @@
   True explicitly to get the previous behaviour.  
   (Vincent Ladeuil, #519319)
 
+* ``bzr export`` to tar file does not fail if any parent directory
+  contains unicode characters. This works around upstream Python bug
+  http://bugs.python.org/issue8396 .
+  (Parth Malwankar, #413406)
+
 * ``bzr update`` when a pending merge in the working tree has been merged
   into the master branch will no longer claim that old commits have become
   pending merges. (Robert Collins, #562079)

=== modified file 'bzrlib/export/tar_exporter.py'
--- a/bzrlib/export/tar_exporter.py	2010-03-25 09:39:03 +0000
+++ b/bzrlib/export/tar_exporter.py	2010-04-14 10:12:22 +0000
@@ -48,7 +48,14 @@
     else:
         if root is None:
             root = export.get_root_name(dest)
-        ball = tarfile.open(dest, 'w:' + compression)
+
+        # tarfile.open goes on to do 'os.getcwd() + dest' for opening
+        # the tar file. With dest being unicode, this throws UnicodeDecodeError
+        # unless we encode dest before passing it on. This works around
+        # upstream python bug http://bugs.python.org/issue8396
+        # (fixed in Python 2.6.5 and 2.7b1)
+        ball = tarfile.open(dest.encode(osutils._fs_enc), 'w:' + compression)
+
     for dp, ie in _export_iter_entries(tree, subdir):
         filename = osutils.pathjoin(root, dp).encode('utf8')
         item = tarfile.TarInfo(filename)

=== modified file 'bzrlib/tests/blackbox/test_export.py'
--- a/bzrlib/tests/blackbox/test_export.py	2010-03-08 02:23:17 +0000
+++ b/bzrlib/tests/blackbox/test_export.py	2010-04-14 08:09:45 +0000
@@ -85,6 +85,15 @@
         self.assertEqual(['test/' + fname.encode('utf8')],
                          sorted(ball.getnames()))
 
+    def test_tar_export_unicode_basedir(self):
+        """Test for bug #413406"""
+        basedir = u'\N{euro sign}'
+        os.mkdir(basedir)
+        os.chdir(basedir)
+        self.run_bzr(['init', 'branch'])
+        os.chdir('branch')
+        self.run_bzr(['export', '--format', 'tgz', u'test.tar.gz'])
+
     def test_zip_export(self):
         tree = self.make_branch_and_tree('zip')
         self.build_tree(['zip/a'])




More information about the bazaar-commits mailing list