Skip to content

fix: preserve absolute root in _strip_protocol so walk("/") works#69

Open
mixilchenko wants to merge 2 commits into
fsspec:mainfrom
mixilchenko:fix/walk-root-strip-protocol
Open

fix: preserve absolute root in _strip_protocol so walk("/") works#69
mixilchenko wants to merge 2 commits into
fsspec:mainfrom
mixilchenko:fix/walk-root-strip-protocol

Conversation

@mixilchenko

@mixilchenko mixilchenko commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

SSHFileSystem.walk("/") listed the home directory instead of the filesystem root, because _strip_protocol("/") collapsed / down to "" and yielded relative paths that exists() didn't recognize.

Fix

_strip_protocol now restores / only when the caller explicitly supplied the absolute root:

explicit absolute root (/, ssh://host/) → /
empty and relative inputs ("", ssh://host, foo/bar) → unchanged, still resolving against the home directory

SSHFileSystem inherited the default root_marker of "", so
_strip_protocol("/") collapsed the root to an empty string. walk("/")
then listed the home directory and produced relative paths that were
not considered to exist. Set root_marker = "/" to keep the root, and
add walk tests covering a nested tree and the root case.

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.

Pull request overview

This PR fixes SSHFileSystem.walk("/") returning incorrect paths by ensuring protocol-stripping preserves the root path. It aligns SSHFileSystem’s root handling with expected absolute-path semantics so directory traversal from / yields paths that exists() recognizes.

Changes:

  • Set SSHFileSystem.root_marker = "/" to prevent _strip_protocol("/") collapsing / into an empty string.
  • Add walk() test coverage for a nested directory tree under a test-specific remote path.
  • Add a regression test ensuring walk("/") yields root == "/" and absolute info["name"] entries that exist.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/test_sshfs.py Adds coverage for walk() on both nested paths and / regression case to ensure returned entries are absolute and valid.
sshfs/spec.py Sets root_marker to preserve / during protocol stripping, fixing root-walk behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mixilchenko

Copy link
Copy Markdown
Contributor Author

@shcheklein I'd like it to be merged and released. What is left?

Comment thread sshfs/spec.py Outdated
Comment thread tests/test_sshfs.py

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR has (unintentionally) higher blast radius. Probably we need some redesign, at least don't set root_marker. Preserve / only when the caller explicitly supplied an absolute root in strip_protocol or something like this. + we need more tests to ensure that the current behavior is not affected.

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread sshfs/spec.py
@mixilchenko mixilchenko changed the title fix: preserve root path in _strip_protocol so walk('/') works fix: preserve absolute root in _strip_protocol so walk("/") works Jul 26, 2026
@mixilchenko

Copy link
Copy Markdown
Contributor Author

@shcheklein updated the pr name and description

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.

3 participants