Skip to content

Try SFTP rename before copying over SSH in mv - #87

Merged
shcheklein merged 4 commits into
fsspec:mainfrom
itzzdev09:mv-sftp-rename-fallback
Nov 29, 2026
Merged

shcheklein merged 4 commits into
fsspec:mainfrom
itzzdev09:mv-sftp-rename-fallback

Conversation

@itzzdev09

Copy link
Copy Markdown
Contributor

Closes #40.

When the server doesn't support the posix-rename extension, mv falls back to running cp over an SSH exec channel. Servers that only allow SFTP refuse that, so mv fails there (the ChannelOpenError: Session request failed from the issue).

Plain SFTP rename is part of the base protocol, so this tries it before the copy. Unlike posix_rename it doesn't replace an existing target, and servers answer that with SFTPFailure (v3) or SFTPFileAlreadyExists (v5+); only those two fall through to the copy + delete. Other errors (missing source, permissions) raise as before.

Tests:

  • test_move_sftp_rename_fallback: with posix_rename unsupported, mv renames without calling _cp_file. Fails on main.
  • The two existing copy-fallback tests now also make rename refuse, so they keep covering the copy path.

pytest tests/test_sshfs.py: 97 passed (python:3.12 Linux container, since mock-ssh-server is Linux only).

posix_rename is an SFTP extension. When a server lacks it, mv ran cp
over an SSH exec channel, which SFTP-only servers reject. Plain rename
is in the base protocol, so try it first and keep the copy for the case
it can't cover: a target that already exists.
@codecov-commenter

codecov-commenter commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.72%. Comparing base (15aac74) to head (62fe9d2).
⚠️ Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_sshfs.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   94.30%   97.72%   +3.41%     
==========================================
  Files          13       13              
  Lines         738     1142     +404     
==========================================
+ Hits          696     1116     +420     
+ Misses         42       26      -16     

☔ 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.

shcheklein and others added 2 commits November 29, 2026 09:40
The test now makes shell commands fail through asyncssh's run, the way
servers that only allow SFTP refuse them (fsspec#40), instead of patching the
internal _cp_file. The comments now say that generic SFTP v3 failures
fall back to the copy, and that no_posix_rename leads to the plain
rename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shcheklein

Copy link
Copy Markdown
Collaborator

Thanks! I merged main, which conflicted on the asyncssh.sftp import (#100 added SFTPFileIsADirectory there), and pushed one cleanup commit:

  • test_move_sftp_rename_fallback now makes shell commands fail through asyncssh's run, the way a server that only allows SFTP refuses them (Use sftp RENAME instead of copy and delete in case of moving a file #40), instead of patching _cp_file. It fails on main with the ChannelOpenError from cp.
  • The comment in _mv says that generic SFTP v3 failures fall back to the copy, since SFTPFailure doesn't only mean the target exists.
  • The no_posix_rename comment no longer says it forces the copy.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Move tests omit the SFTPFileAlreadyExists fallback and propagation of unrelated rename errors, leaving the new exception filter insufficiently covered against regressions.

1 open issue
What changed in this PR

This PR addresses #40 by letting mv try standard SFTP rename when posix_rename is unavailable, supporting SFTP-only servers without requiring SSH shell access for that path.

Changes:

  • Try plain SFTP rename before falling back to copy-and-delete.
  • Retain the copy fallback for SFTPFailure and SFTPFileAlreadyExists.
  • Add an SFTP-only move regression test and adjust existing copy-fallback tests.
File Description
tests/​test_sshfs.py Tests the SFTP rename fallback and updates fixtures to preserve copy-path coverage.
sshfs/​spec.py Adds standard SFTP rename between POSIX rename and SSH copy-and-delete.

Review effort: Balanced

Comment thread sshfs/spec.py Resolved
The copy fallback tests now run with rename refusing the target both
ways servers report it: SFTPFailure in SFTP v3 and SFTPFileAlreadyExists
in later versions. A new test checks that other rename errors reach the
caller without copying.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the SFTP rename fallback change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shcheklein
shcheklein merged commit c365631 into fsspec:main Nov 29, 2026
9 checks passed
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.

Use sftp RENAME instead of copy and delete in case of moving a file

4 participants