Skip to content

fix: preserve source file when move fallback copy fails - #83

Merged
shcheklein merged 2 commits into
fsspec:mainfrom
Rudra-G-23:fix/81-preserve-source-on-mv-copy-failure
Nov 17, 2026
Merged

shcheklein merged 2 commits into
fsspec:mainfrom
Rudra-G-23:fix/81-preserve-source-on-mv-copy-failure

Conversation

@Rudra-G-23

Copy link
Copy Markdown
Contributor

Summary

Prevent SSHFileSystem.mv() from deleting the source when its copy fallback fails.

Fixes #81

Root Cause

The fallback used finally to remove the source, causing deletion even when the SSH cp command raised an error.

Changes

  • Remove the source only after _cp_file() succeeds.
  • Add regression coverage for failed and successful fallback moves, POSIX rename behavior, and original copy-error propagation.

Testing

  • python -m pytest tests/test_sshfs.py -q
  • python -m pytest -q
  • Black, isort, mdformat, codespell
  • git diff --check

@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
tests/test_sshfs.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
- Coverage   94.30%   93.95%   -0.36%     
==========================================
  Files          13       13              
  Lines         738      877     +139     
==========================================
+ Hits          696      824     +128     
- Misses         42       53      +11     

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

- Rename test_move to test_move_posix_rename. A real rename keeps the
  file's timestamps, so compare info exactly instead of allowing a
  1-second drift (only needed when mv took the copy fallback).
- Share the unsupported posix_rename patch via a no_posix_rename
  fixture.
- Drop the call-tracking wrappers; the content assertions already show
  the source survives and the copy isn't used.
- Drop the mocked copy-error test; the real copy-failure test covers it.

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

Copy link
Copy Markdown
Collaborator

Thanks for the fix! I pushed a small cleanup of the tests on top (2313303):

  • test_move is now test_move_posix_rename. The 1-second timestamp tolerance was only needed because, on the mock server, mv used to go through the copy fallback. With your posix_rename patch it's a real rename, so the file info now has to match exactly.
  • The "posix_rename unsupported" patch is shared through a no_posix_rename fixture.
  • I dropped the call-tracking wrappers and the mocked copy-error test. The content checks and the real copy-failure test already cover them.

I'll merge once CI is green.

@shcheklein
shcheklein merged commit 681dce8 into fsspec:main Nov 17, 2026
9 checks passed
shcheklein added a commit to xcRRRRt/fsspec-sshfs that referenced this pull request Nov 17, 2026
Resolve the move-test conflict with fsspec#83: keep main's
test_move_copy_fallback and test_move_copy_fallback_failure_keeps_source,
and drop test_move_fallback_posix_rename_unsupported, which duplicated
test_move_copy_fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

mv fallback deletes the source file when the copy fails

3 participants