Skip to content

mkdir(): allow a missing SFTP channel (#394) - #436

Closed
danielagbo888-png wants to merge 2 commits into
ParallelSSH:masterfrom
danielagbo888-png:fix/394-mkdir-sftp-none
Closed

danielagbo888-png wants to merge 2 commits into
ParallelSSH:masterfrom
danielagbo888-png:fix/394-mkdir-sftp-none

Conversation

@danielagbo888-png

@danielagbo888-png danielagbo888-png commented Dec 5, 2026 •

Copy link
Copy Markdown

mkdir() now creates its own SFTP channel when one isn't supplied, as raised in #394.

copy_file() already does sftp = self._make_sftp() if sftp is None else sftp. mkdir() didn't, so creating a directory meant reaching into _make_sftp() yourself first.

Both call forms work now:

client.mkdir('/srv/app')          # channel created for this call
client.mkdir(sftp, '/srv/app')    # historical form, unchanged

They're told apart by directory is None and isinstance(sftp, str) — an SFTP channel is never a string, so the two can't be confused.

I kept the parameter order rather than moving to mkdir(directory, sftp=None), so no existing positional caller breaks. That's the one decision I'd understand pushback on: the clean signature reads better and would match copy_file(), but it needs a breaking-change note, and #394 already suggested doing that "in a later version". Happy to flip it here if you'd rather take the break now.

Tests — tests/test_native_single_mkdir.py, 4 tests, no SSH server needed (client built with object.__new__, channel faked):

  • mkdir('/tmp/remote-dir') creates the channel once and makes each missing parent
  • relative paths still resolve from .
  • mkdir(sftp, path) does not create a channel
  • mkdir() raises TypeError instead of an AttributeError on None

On master two of them fail with TypeError: mkdir() missing 1 required positional argument: 'directory'. With the patch all four pass, and the non-server suite (25 tests) still passes.

Only the native client is touched: the ssh/libssh client has no SFTP methods, so there was nothing to mirror there. pathlib.Path arguments were already unsupported before this change (the body calls .split('/')), so this doesn't regress them — worth a separate issue if you want os.PathLike support.

Integration coverage — ci/integration_tests/libssh2_clients/test_single_client.py::test_sftp_mkdir_without_channel calls mkdir(path) against the repo's embedded sshd and asserts the parent chain exists on disk. It fails on master with the same TypeError, so the new form is covered both with and without a channel in hand.

CI on this PR: CircleCI 3.8 / 3.11 / 3.12 / 3.13, Hound and codecov all green, and codecov reports every modified line covered.

@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (6bfe5f9) to head (13ca1c2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
- Coverage   99.47%   99.41%   -0.06%     
==========================================
  Files          18       18              
  Lines        1708     1713       +5     
==========================================
+ Hits         1699     1703       +4     
- Misses          9       10       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danielagbo888-png

Copy link
Copy Markdown
Author

Closing this as a duplicate of #432, which I missed before opening it — it covers the same change and also drops the channel requirement from sftp_put/sftp_get. No reason to make you compare two diffs for the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant