Skip to content

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

Open
itzzdev09 wants to merge 1 commit into
fsspec:mainfrom
itzzdev09:mv-sftp-rename-fallback
Open

itzzdev09 wants to merge 1 commit into
fsspec:mainfrom
itzzdev09:mv-sftp-rename-fallback

Conversation

@itzzdev09

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.52%. Comparing base (15aac74) to head (1e90e61).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_sshfs.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #87      +/-   ##
==========================================
+ Coverage   94.30%   94.52%   +0.21%     
==========================================
  Files          13       13              
  Lines         738      949     +211     
==========================================
+ Hits          696      897     +201     
- Misses         42       52      +10     

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

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

2 participants