[PATCH] FTP transport append()
Alexandre Saint
stalst at gmail.com
Sun Apr 16 12:15:12 BST 2006
Hi,
Here's another patch for the FTP transport:
- Implemented a append() method. So pushing with knit format is working now.
- Fixed _abspath() to return the given path when it is given a absolute path.
Cheers,
Alex.
--
alex
-------------- next part --------------
=== modified file 'a/bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py
+++ b/bzrlib/transport/ftp.py
@@ -134,8 +134,8 @@
relpath_parts = relpath[:]
if len(relpath_parts) > 1:
if relpath_parts[0] == '':
- raise ValueError("path %r within branch %r seems to be absolute"
- % (relpath, self._path))
+ # the path seems to be absolute
+ return relpath
basepath = self._path.split('/')
if len(basepath) > 0 and basepath[-1] == '':
basepath = basepath[:-1]
@@ -303,11 +303,39 @@
raise TransportError(msg="Cannot remove directory at %s" % \
self._abspath(rel_path), extra=str(e))
- def append(self, relpath, f):
+ def append(self, relpath, fp, retries=0):
"""Append the text in the file-like object into the final
location.
"""
- raise TransportNotPossible('ftp does not support append()')
+ if isinstance(fp, basestring):
+ fp = StringIO(fp)
+ fp.seek(0)
+ try:
+ abspath = self._abspath(relpath)
+ mutter("FTP appe to %s" % abspath)
+ ftp = self._get_FTP()
+ if self.has(abspath):
+ length = ftp.size(abspath)
+ else:
+ length = 0
+ ftp.voidcmd("TYPE I")
+ cmd = "APPE %s" % abspath
+ conn = ftp.transfercmd(cmd)
+ conn.sendall(fp.read())
+ conn.close()
+ ftp.getresp()
+ return length
+ except ftplib.error_perm, e:
+ FtpTransportError("Error appending data to %s" % abspath,
+ orig_error=e)
+ except ftplib.error_temp, e:
+ if retries > _number_of_retries:
+ raise TransportError("FTP temporary error during APPEND %s." \
+ "Aborting." % self.abspath(relpath), orig_error=e)
+ else:
+ warning("FTP temporary error: %s. Retrying." % str(e))
+ self._FTP_instance = None
+ self.append(relpath, fp, retries+1)
def copy(self, rel_from, rel_to):
"""Copy the item at rel_from to the location at rel_to"""
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060416/76acabe9/attachment.pgp
More information about the bazaar
mailing list