mirror of
https://github.com/ARM-software/devlib.git
synced 2025-03-04 17:27:51 +00:00
ssh: Fix folder pull on SSH connection
Paramiko seems to have had a slight change in behavior that broke devlib: to save a remote command execution, we attempt to pull any path as file first, and then as a folder if the former failed. This is now broken as paramiko will create an empty destination file when trying to pull as a file. When we attempt again to pull as folder, the destination exists already (empty file) and we raise an exception. To fix that, make sure we cleanup any attempt after pulling as a file before trying again.
This commit is contained in:
parent
facd251edb
commit
df1b5ef4a2
@ -499,7 +499,18 @@ class SshConnection(SshConnectionBase):
|
|||||||
push(sftp, src, dst, callback)
|
push(sftp, src, dst, callback)
|
||||||
|
|
||||||
def _pull_file(self, sftp, src, dst, callback):
|
def _pull_file(self, sftp, src, dst, callback):
|
||||||
sftp.get(src, dst, callback=callback)
|
try:
|
||||||
|
sftp.get(src, dst, callback=callback)
|
||||||
|
except Exception as e:
|
||||||
|
# A file may have been created by Paramiko, but we want to clean
|
||||||
|
# that up, particularly if we tried to pull a folder and failed,
|
||||||
|
# otherwise this will make subsequent attempts at pulling the
|
||||||
|
# folder fail since the destination will exist.
|
||||||
|
try:
|
||||||
|
os.remove(dst)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise e
|
||||||
|
|
||||||
def _pull_folder(self, sftp, src, dst, callback):
|
def _pull_folder(self, sftp, src, dst, callback):
|
||||||
os.makedirs(dst)
|
os.makedirs(dst)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user