Skip to content

Commit eeea24f

Browse files
authored
Merge pull request #620 from Jakuje/scp-crash
2 parents 7f14739 + 6b6e566 commit eeea24f

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
620.bugfix.rst
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
620.bugfix.rst
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Downloading non-existent remote files via SCP no longer crashes the program -- by :user:`Jakuje`.

src/pylibsshext/scp.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cdef class SCP:
9696
:param local_file: The path on the local host where the file should be placed
9797
:type local_file: str
9898
"""
99-
cdef char *read_buffer
99+
cdef char *read_buffer = NULL
100100

101101
remote_file_b = remote_file
102102
if isinstance(remote_file_b, unicode):

tests/unit/scp_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
"""Tests suite for scp."""
44

5+
import os
56
import uuid
67

78
import pytest
89

10+
from pylibsshext.errors import LibsshSCPException
11+
912

1013
@pytest.fixture
1114
def ssh_scp(ssh_client_session):
@@ -57,3 +60,18 @@ def test_get(dst_path, src_path, ssh_scp, transmit_payload):
5760
"""Check that SCP file download works."""
5861
ssh_scp.get(str(src_path), str(dst_path))
5962
assert dst_path.read_bytes() == transmit_payload
63+
64+
65+
@pytest.fixture
66+
def path_to_non_existent_src_file(tmp_path):
67+
"""Return a remote path that does not exist."""
68+
path = tmp_path / 'non-existing.txt'
69+
assert not path.exists()
70+
return path
71+
72+
73+
def test_copy_from_non_existent_remote_path(path_to_non_existent_src_file, ssh_scp):
74+
"""Check that SCP file download raises exception if the remote file is missing."""
75+
error_msg = '^Error receiving information about file:'
76+
with pytest.raises(LibsshSCPException, match=error_msg):
77+
ssh_scp.get(str(path_to_non_existent_src_file), os.devnull)

0 commit comments

Comments
 (0)