Skip to content

fix: makedirs of the home directory or the root with exist_ok - #99

Merged
shcheklein merged 1 commit into
mainfrom
fix/makedirs-home-root
Nov 29, 2026
Merged

shcheklein merged 1 commit into
mainfrom
fix/makedirs-home-root

Conversation

@shcheklein

Copy link
Copy Markdown
Collaborator

_parent returns "" for a top-level path, and makedirs("", exist_ok=True) fails with FileNotFoundError, because asyncssh sends mkdir(""), which the server rejects. fsspec's generic code creates parent directories with makedirs(fs._parent(path), exist_ok=True), so this failed:

fs.get_mapper("")["a"] = b"data"  # FileNotFoundError

makedirs now returns early for "" (the home directory) and "/" when exist_ok is set, since both always exist. With exist_ok=False it behaves as before. "/" already worked against the test server, but skipping it also saves requests and doesn't depend on how a server answers mkdir("/").

The _parent checks that #91 added to put_file and pipe_file become redundant with this. #89's PR removes them.

The test for "" and the get_mapper test fail on main.

Fixes #93.

🤖 Generated with Claude Code

_parent returns "" for a top-level path, and makedirs("", exist_ok=True)
failed with FileNotFoundError: asyncssh sends mkdir(""), which the
server rejects. fsspec's generic code creates parents with
makedirs(_parent(path), exist_ok=True), so writing a top-level key
through get_mapper("") failed. makedirs now returns early for "" and
"/" when exist_ok is set, since both always exist.

Fixes #93.

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.

🟡 Changes recommended

The guard omits supported bytes paths, so makedirs(b"", exist_ok=True) still sends a rejected empty-path request and the home-directory fix remains unavailable when path_encoding=None.

1 open issue
What changed in this PR

This PR fixes home-directory creation for fsspec’s parent-directory workflow, enabling writes through get_mapper("") and addressing #93.

Changes:

  • Skip directory creation for "" and "/" when exist_ok=True, while preserving strict creation behavior.
  • Add regression tests for home/root paths and top-level mapper writes.
File Description
tests/​test_sshfs.py Tests home/root directory creation and top-level mapper writes.
sshfs/​spec.py Adds an early return for home/root paths when exist_ok=True.

Review effort: Balanced

Comment thread sshfs/spec.py Resolved
@shcheklein
shcheklein requested a balanced review from Copilot November 29, 2026 17:27
@shcheklein shcheklein self-assigned this Nov 29, 2026
@shcheklein
shcheklein merged commit 5fd5835 into main Nov 29, 2026
12 checks passed

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

No active review issues are reported for the home- and root-directory handling change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@shcheklein
shcheklein deleted the fix/makedirs-home-root branch November 29, 2026 17:39
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.

makedirs fails for the parent of a top-level path, so get_mapper("") can't write keys

2 participants