Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash if remote file does not exist #620

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog-fragments/208.bugfix.rst
1 change: 1 addition & 0 deletions docs/changelog-fragments/325.bugfix.rst
1 change: 1 addition & 0 deletions docs/changelog-fragments/620.bugfix.rst
Jakuje marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Downloading non-existent remote files via SCP no longer crashes the program -- by :user:`Jakuje`.
2 changes: 1 addition & 1 deletion src/pylibsshext/scp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cdef class SCP:
:param local_file: The path on the local host where the file should be placed
:type local_file: str
"""
cdef char *read_buffer
cdef char *read_buffer = NULL

remote_file_b = remote_file
if isinstance(remote_file_b, unicode):
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/scp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

"""Tests suite for scp."""

import os
import uuid

webknjaz marked this conversation as resolved.
Show resolved Hide resolved
import pytest

from pylibsshext.errors import LibsshSCPException


@pytest.fixture
def ssh_scp(ssh_client_session):
Expand Down Expand Up @@ -57,3 +60,18 @@ def test_get(dst_path, src_path, ssh_scp, transmit_payload):
"""Check that SCP file download works."""
ssh_scp.get(str(src_path), str(dst_path))
assert dst_path.read_bytes() == transmit_payload


@pytest.fixture
def path_to_non_existent_src_file(tmp_path):
"""Return a remote path that does not exist."""
path = tmp_path / 'non-existing.txt'
Jakuje marked this conversation as resolved.
Show resolved Hide resolved
assert not path.exists()
return path


def test_copy_from_non_existent_remote_path(path_to_non_existent_src_file, ssh_scp):
"""Check that SCP file download raises exception if the remote file is missing."""
error_msg = '^Error receiving information about file:'
with pytest.raises(LibsshSCPException, match=error_msg):
ssh_scp.get(str(path_to_non_existent_src_file), os.devnull)
Loading