From 1c0223556f021cb518b68f4e64b8a6aa9f40c7de Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 11 Sep 2023 14:01:55 +0100 Subject: [PATCH] utils/ssh: Fix SSHTransferHandle when using SCP Using SSHConnection(use_scp=True) lead to an exception: UnboundLocalError: local variable 'handle' referenced before assignment This is cause by some (false) cyclic dependency between initialization of SSHTransferHandle and creation of the SCPClient. We can fix that by adding a level of indirection to tie together both objects. --- devlib/utils/ssh.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index 23b0a6e..0feceaf 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -525,7 +525,9 @@ class SshConnection(SshConnectionBase): # No timeout elif self.use_scp: - scp = self._get_scp(timeout, callback=handle.progress_cb) + def progress_cb(*args, **kwargs): + return handle.progress_cb(*args, **kwargs) + scp = self._get_scp(timeout, callback=progress_cb) handle, cm = make_handle(scp) scp_cmd = getattr(scp, 'put' if action == 'push' else 'get')