[MERGE] transport.list_dir should always return url-escaped names.
Andrew Bennetts
andrew at canonical.com
Tue Aug 8 07:00:35 BST 2006
Working on the smart server, I saw that the return values from list_dir were
inconsistent. I've added a test to ensure that it always returns url-escaped
names, and fixed the two broken transports.
See attached diff.
-Andrew.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- bzrlib/tests/test_transport_implementations.py 2006-07-28 16:52:19 +0000
+++ bzrlib/tests/test_transport_implementations.py 2006-08-08 05:40:36 +0000
@@ -733,7 +733,7 @@
os.mkdir('wd')
t = t.clone('wd')
- self.assertEqual([], sorted_list(u'.'))
+ self.assertEqual([], sorted_list('.'))
# c2 is precisely one letter longer than c here to test that
# suffixing is not confused.
if not t.is_readonly():
@@ -741,8 +741,8 @@
else:
self.build_tree(['wd/a', 'wd/b', 'wd/c/', 'wd/c/d', 'wd/c/e', 'wd/c2/'])
- self.assertEqual([u'a', u'b', u'c', u'c2'], sorted_list(u'.'))
- self.assertEqual([u'd', u'e'], sorted_list(u'c'))
+ self.assertEqual(['a', 'b', 'c', 'c2'], sorted_list('.'))
+ self.assertEqual(['d', 'e'], sorted_list('c'))
if not t.is_readonly():
t.delete('c/d')
@@ -751,13 +751,25 @@
os.unlink('wd/c/d')
os.unlink('wd/b')
- self.assertEqual([u'a', u'c', u'c2'], sorted_list('.'))
- self.assertEqual([u'e'], sorted_list(u'c'))
+ self.assertEqual(['a', 'c', 'c2'], sorted_list('.'))
+ self.assertEqual(['e'], sorted_list('c'))
self.assertListRaises(PathError, t.list_dir, 'q')
self.assertListRaises(PathError, t.list_dir, 'c/f')
self.assertListRaises(PathError, t.list_dir, 'a')
+ def test_list_dir_result_is_url_escaped(self):
+ t = self.get_transport()
+ if not t.listable():
+ raise TestSkipped("transport not listable")
+
+ if not t.is_readonly():
+ self.build_tree(['a/', 'a/%'], transport=t)
+ else:
+ self.build_tree(['a/', 'a/%'])
+
+ self.assertEqual(['%25'], list(t.list_dir('a')))
+
def test_clone(self):
# TODO: Test that clone moves up and down the filesystem
t1 = self.get_transport()
=== modified file 'bzrlib/transport/memory.py'
--- bzrlib/transport/memory.py 2006-07-28 16:05:23 +0000
+++ bzrlib/transport/memory.py 2006-08-08 05:52:07 +0000
@@ -173,7 +173,7 @@
len(path) > len(_abspath) and
path[len(_abspath)] == '/'):
result.append(path[len(_abspath) + 1:])
- return result
+ return map(urlutils.escape, result)
def rename(self, rel_from, rel_to):
"""Rename a file or directory; fail if the destination exists"""
=== modified file 'bzrlib/transport/sftp.py'
--- bzrlib/transport/sftp.py 2006-08-08 02:31:24 +0000
+++ bzrlib/transport/sftp.py 2006-08-08 05:53:38 +0000
@@ -724,7 +724,7 @@
# does anything actually use this?
path = self._remote_path(relpath)
try:
- return self._sftp.listdir(path)
+ return map(urlutils.escape, self._sftp.listdir(path))
except (IOError, paramiko.SSHException), e:
self._translate_io_exception(e, path, ': failed to list_dir')
More information about the bazaar
mailing list