Fix file_get_lib() so it behaves the same way with sftp as it does with other protocols.
authorZac Medico <zmedico@gentoo.org>
Mon, 25 Jun 2007 04:47:35 +0000 (04:47 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 25 Jun 2007 04:47:35 +0000 (04:47 -0000)
svn path=/main/trunk/; revision=7024

pym/portage/getbinpkg.py

index a1fec9d20f7a90bc746276a225955a7c31c2d24c..b5a15aaaf9daf4c00021edcac11f8c66e6ad1a4d 100644 (file)
@@ -419,7 +419,22 @@ def file_get_lib(baseurl,dest,conn=None):
        elif protocol in ["ftp"]:
                data,rc,msg = make_ftp_request(conn, address, dest=dest)
        elif protocol == "sftp":
-               conn.get(address, dest)
+               rc = 0
+               try:
+                       f = conn.open(address)
+               except Exception:
+                       rc = 1
+               else:
+                       try:
+                               if dest:
+                                       bufsize = 8192
+                                       while True:
+                                               data = f.read(bufsize)
+                                               if not data:
+                                                       break
+                                               dest.write(data)
+                       finally:
+                               f.close()
        else:
                raise TypeError, "Unknown protocol. '%s'" % protocol