Repository navigation
fix: upload to relative and top-level paths - #91
Conversation
put_file and pipe_file create the parent directory first. For a
relative path such as "file" or a top-level path such as "/file",
_parent returns "", and asyncssh's makedirs("") sends mkdir(""), which
the server rejects, so the upload failed with FileNotFoundError. The
parent of such a path is the home directory or the root, which always
exists, so skip makedirs when the parent is "".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Leave put_file and pipe_file as they are on main, and give bytes paths in _parent the parents fsspec gives str paths, so str behavior doesn't change. Uploads to relative and top-level paths are fixed in fsspec#91, and "--" before paths in shell commands is added in fsspec#92. The upload test uses absolute paths, since relative uploads depend on fsspec#91. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein
left a comment
There was a problem hiding this comment.
(AI-generated review by Copilot)
Clean targeted fix for relative and top-level uploads (and works with b"" from #86 as well). Inline notes on _makedirs / _parent at the bigger-picture level, removing the internal _makedirs mock in test_put_file_top_level_path, and covering pipe_file("/file", ...).
| await self._makedirs(self._parent(rpath), exist_ok=True) | ||
| # "" means the parent is the root or the home directory, which exist | ||
| if parent := self._parent(rpath): | ||
| await self._makedirs(parent, exist_ok=True) |
There was a problem hiding this comment.
[AI-generated — Copilot] Gap & bigger picture:
- Skipping
_makedirshere (and in_pipe_file) fixes uploads and avoids acquiring an SFTP channel when no parent needs creating, and also works forb""once fix: support bytes paths in native filesystem operations #86 lands. - Gap: Direct calls like
fs.makedirs("", exist_ok=True)orfs.makedirs("/", exist_ok=True)(or fsspec generic code callingmakedirs(self._parent(path), exist_ok=True)) still fail:asyncsshsendsmkdir("")(FileNotFoundError) andmkdir("/")(which raisesSFTPPermissionDeniedon non-root servers becausei == lastinasyncssh'smakedirs). - Bigger picture:
_parent("/file")returning""conflates/(root) with""(home dir), even though_strip_protocolexplicitly distinguishes them. Long-term, having_parentreturn"/"for"/file"and""for"file"(and skipping_makedirson("", "/", b"", b"/"), or handling empty/root whenexist_ok=Truein_makedirs) avoids that ambiguity across all callers.
There was a problem hiding this comment.
Direct makedirs("") calls are a separate, older bug. fsspec's FSMap hits it too: fs.get_mapper("")["a"] = b"data" fails on main and with this PR. Filed as #93, along with the _parent("/a") == "" ambiguity. This PR stays scoped to put_file and pipe_file.
makedirs("/", exist_ok=True) works against the test server: mkdir("/") gets a generic failure, and asyncssh then finds a directory. A server that answers permission denied would fail it, so #93 suggests handling both "" and "/" in _makedirs.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change to skip directory creation when an upload path has no parent.
No open issues 🎉
What changed in this PR
This PR fixes uploads to relative and top-level paths by avoiding directory creation when the parent path is empty.
Changes:
- Skip
_makedirsfor empty parent paths in bothput_fileandpipe_file. - Add regression tests for relative uploads through both methods and a stubbed top-level
put_fileupload.
| File | Description |
|---|---|
| tests/test_sshfs.py | Adds regression coverage for relative and top-level upload paths. |
| sshfs/spec.py | Guards parent-directory creation in both upload methods. |
Review effort: Balanced
- Split the relative-path test into put_file and pipe_file tests, each
next to its existing test.
- The top-level put_file test no longer mocks _makedirs. It stubs only
SFTPClient.put, so without the fix it fails on the real makedirs("").
- Add the same top-level test for pipe_file, which stubs SFTPClient.open.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
put_fileandpipe_filecreate the parent directory with_makedirs(self._parent(path), exist_ok=True). For a relative path such as"file"or a top-level path such as"/file",_parentreturns"", and asyncssh'smakedirs("")sendsmkdir(""), which the server rejects. So these uploads fail withFileNotFoundError:The parent of such a path is the home directory or the root, which always exists, so this skips
_makedirswhen_parentreturns"".Split out of #86.
🤖 Generated with Claude Code