Rev 3512: Ensure that ftp transport are always in binary mode. in file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Feb 26 19:30:07 GMT 2009
At file:///net/bigmamac/Volumes/home/vila/src/bzr/experimental/more-ftp/
------------------------------------------------------------
revno: 3512
revision-id: v.ladeuil+lp at free.fr-20090226193006-mleqjssvlnebdeea
parent: v.ladeuil+lp at free.fr-20090226192049-ffg6266tv4z4i0ty
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: fix-chmod
timestamp: Thu 2009-02-26 20:30:06 +0100
message:
Ensure that ftp transport are always in binary mode.
* bzrlib/transport/ftp/__init__.py:
(FtpStatResult.__init__): Rename 'relpath' parameter to 'baspath'
as this is really midsleading.
(FtpTransport._create_connection): Set binary mode from the start.
(FtpTransport.list_dir): Restore binary mode as ftplib.lnst
doesn't.
(FtpTransport._try_append): No need to force binary mode anymore.
* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_connect_twice_is_same_content): Mention that
the test is brittle.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py 2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/test_transport_implementations.py 2009-02-26 19:30:06 +0000
@@ -1115,6 +1115,7 @@
self.assertListRaises(PathError, t.list_dir, 'q')
self.assertListRaises(PathError, t.list_dir, 'c/f')
+ # 'a' is a file, list_dir should raise an error
self.assertListRaises(PathError, t.list_dir, 'a')
def test_list_dir_result_is_url_escaped(self):
@@ -1506,7 +1507,10 @@
transport.put_bytes('foo', 'bar')
transport3 = self.get_transport()
self.check_transport_contents('bar', transport3, 'foo')
- # its base should be usable.
+ # its base should be usable. XXX: This is true only if we don't use
+ # auhentication, otherwise 'base' doesn't mention the password and we
+ # can't access it anymore since the password is lost (it *could* be
+ # mentioned in the url given by the test server) --vila 090226
transport4 = get_transport(transport.base)
self.check_transport_contents('bar', transport4, 'foo')
=== modified file 'bzrlib/transport/ftp/__init__.py'
--- a/bzrlib/transport/ftp/__init__.py 2009-01-17 01:30:58 +0000
+++ b/bzrlib/transport/ftp/__init__.py 2009-02-26 19:30:06 +0000
@@ -63,14 +63,15 @@
class FtpStatResult(object):
- def __init__(self, f, relpath):
+
+ def __init__(self, f, abspath):
try:
- self.st_size = f.size(relpath)
+ self.st_size = f.size(abspath)
self.st_mode = stat.S_IFREG
except ftplib.error_perm:
pwd = f.pwd()
try:
- f.cwd(relpath)
+ f.cwd(abspath)
self.st_mode = stat.S_IFDIR
finally:
f.cwd(pwd)
@@ -145,6 +146,8 @@
port=self._port)
connection.login(user=user, passwd=password)
connection.set_pasv(not self.is_active)
+ # binary mode is the default
+ connection.voidcmd('TYPE I')
except socket.error, e:
raise errors.SocketConnectionError(self._host, self._port,
msg='Unable to connect to',
@@ -409,7 +412,6 @@
abspath = self._remote_path(relpath)
mutter("FTP appe (try %d) to %s", retries, abspath)
ftp = self._get_FTP()
- ftp.voidcmd("TYPE I")
cmd = "APPE %s" % abspath
conn = ftp.transfercmd(cmd)
conn.sendall(text)
@@ -530,6 +532,11 @@
str(e))
return []
raise
+ finally:
+ # Restore binary mode as nlst switch to ascii mode to retrieve file
+ # list
+ f.voidcmd('TYPE I')
+
# If FTP.nlst returns paths prefixed by relpath, strip 'em
if paths and paths[0].startswith(basepath):
entries = [path[len(basepath)+1:] for path in paths]
More information about the bazaar-commits
mailing list