Fix file_get_lib() so it behaves the same way with sftp as it does with other protoco...
authorZac Medico <zmedico@gentoo.org>
Mon, 25 Jun 2007 04:50:48 +0000 (04:50 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 25 Jun 2007 04:50:48 +0000 (04:50 -0000)
svn path=/main/branches/2.1.2/; revision=7026

pym/getbinpkg.py

index 8bd43f29c4ce8bce21e025d32aa293a005e1f60b..9484d1d16d0a98cd73e1d148c04d7554c4b4eec9 100644 (file)
@@ -419,7 +419,24 @@ 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 SystemExit:
+                       raise
+               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