You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There was no way to name a path in the home directory in a URL. ssh://host/~/file became /~/file, a directory named ~ at the root (#55).
A leading ~ element now means the home directory, in URLs and in paths alike. _strip_protocol turns it into ., which SFTP servers resolve to the home directory:
Input
Path used
ssh://host/~/data/file
./data/file
~/data/file
./data/file
ssh://host/~, ~
. (the home directory)
~/~/file (a directory named ~)
./~/file
ssh://host/data/file
/data/file (unchanged)
/~/file (a plain path, such as one from ls("/"))
/~/file (unchanged: a directory named ~ at the root)
~data, data/~/file
unchanged
makedirs and uploads treat . like "": it always exists, so it's never created. fs.get_mapper("") roots the mapper at ., so a key named ~ is a file there too. Results keep the ./ prefix: ls("~") returns ./a.txt, so glob("~/*") matches every entry, and a ~ element after the prefix stays a file named ~ when the path is stripped again, as rm does. Listings of "" (#106) name a file called ~./~, so find("") doesn't recurse into the home directory through it.
This follows curl, which treats sftp://host/~/file as home-relative and other URL paths as absolute, and the expired IETF draft for sftp:// URIs, which uses the same ~ element. fsspec's local filesystem also expands ~ in paths. OpenSSH's sftp and scp resolve every URL path against the home directory (absolute paths need //). Switching to that would change where existing URLs like ssh://host/data/file point, so URL paths stay absolute, and the class docstring now says so.
The branch includes #106's commit, so merge #106 first. Checked against OpenSSH 10.0: cat_file, ls, info, glob, find, makedirs, pipe_file and rm work with ~ paths, and rm("~/~/a.txt") removes only the file inside the ~ directory. The new tests fail on main.
sshfs uses "" for the home directory, but ls and info sent it to the
server as is, and an empty path isn't valid there: OpenSSH's
sftp-server fails with ENOENT. So ls(""), info("") and
ls("ssh://host") raised FileNotFoundError, and find("") returned
nothing. They now send ".", which servers resolve to the home
directory. Listing names stay relative, and info("") keeps the name ""
so it isn't confused with "/".
Fixes#105.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ssh://host/~/file, ~/file and ~ now name paths in the home directory:
_strip_protocol turns them into relative paths, which SFTP servers
resolve against it. curl's sftp URLs and the IETF draft for sftp URIs
use the same ~ element, and fsspec's local filesystem expands ~ in
paths. Other URL paths stay absolute.
Fixes#55.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds leading ~ support to SSHFileSystem paths and URLs, addressing #55 while preserving absolute paths for ordinary URLs. Listing the home directory itself remains covered by #106.
Changes:
Converts a leading whole ~ component into a home-relative path.
Documents URL path behavior and differences from OpenSSH.
Adds normalization tests and a file-read test for home-relative paths.
File
Description
tests/test_sshfs.py
Tests tilde normalization, unchanged paths, and home-relative file reads.
sshfs/spec.py
Implements leading-tilde handling and documents path semantics.
_strip_protocol turned ~/~/victim into ~/victim, and methods that strip
a path again, such as rm and then _rm_file, turned that into victim, so
rm("~/~/victim") deleted victim in the home directory. Listing the
home directory also named a file called ~ as "~", which meant the home
directory when passed back, so find("~") recursed into it forever. A
relative path whose first element is a file named ~ now starts with
"./", both when stripped and in listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Tilde escaping remains inconsistent, causing absolute /~ listing entries to resolve to the home directory and home-relative globs to omit literal ~ files.
This only escapes relative names, although _strip_protocol also interprets /~ as the home directory. If the server root contains a literal directory named ~, ls("/") returns /~, and passing that name to info, cat_file, or recursive traversal redirects it to the home directory. Escape absolute leading ~ elements too, for example as /./~, so listing results continue to identify the original entry.
With ~ mapped to "", glob("~/*") became the pattern "*", which
doesn't match the escaped name "./~" of a file named ~ in the home
directory, so the glob left it out. ~ now becomes "." and ~/x becomes
./x: servers resolve "." to the home directory, listings of ~ name every
entry with "./", and a "~" element after it stays a file named ~
without a special case. Listings of "" still escape a file named ~.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Unresolved tilde-path handling can redirect operations on root listing entries to the user's home directory and misaddress literal ~ keys in empty-root mappers.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Escape root listing paths that begin with a literal ~
sshfs/spec.py:55
A literal ~ entry at the filesystem root is still returned as /~ by ls('/'). The new _strip_protocol turns that name into ., so passing the listing result to info or rm(..., recursive=True) targets the user's home directory instead of the listed entry. Escape absolute /~ and /~/... listing names too, for example as /./~, so returned paths continue to identify the correct object.
Normalize empty mapper roots to preserve literal ~ keys
sshfs/spec.py:170
This also changes literal keys in an empty-root mapper: if the home directory contains a file named ~, fs.get_mapper("")["~"] now targets . instead of that file, while iteration exposes the key as ./~. FSMap's key construction on fsspec's default branch concatenates the empty root prefix directly with the key. Normalize an empty mapper root to . before constructing FSMap, so literal keys receive a protective ./ path prefix without changing their names.
Only a URL's path starts with "/" before a home-directory "~", so a
plain /~ or /~/file, such as a root entry from ls("/"), now stays a file
named ~ at the root. Before, rm("/~/file") targeted the home directory.
Since ~ becomes ".", makedirs skips "." with exist_ok like "", and
_upload treats a "." parent like "": a missing file under ~ raises
without creating "." and retrying.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Root listing entries named ~: fixed in f84e26e. A plain /~ or /~/... now stays a path at the root, and only a URL's /~/ means the home directory. So the /~ that ls("/") returns names the root entry.
A literal ~ key in a mapper rooted at "": leaving this as is. A relative path that starts with ~ means the home directory by design, the same way fsspec's local filesystem expands ~. A key named exactly ~ in a mapper rooted at the home directory is the one case that collides. fs.get_mapper(".") addresses it as ./~. Overriding get_mapper wouldn't cover fsspec.get_mapper("ssh://host") or an FSMap built directly.
FSMap builds paths by joining its root to each key, so in a mapper
rooted at "" the key "~" became the path "~", which means the home
directory, while iteration listed that file as "./~".
SSHFileSystem.get_mapper now roots a home-directory mapper at ".", so
keys become ./key paths and iteration still returns plain names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The get_mapper override breaks compatibility with supported positional arguments, causing previously valid calls to raise TypeError instead of creating a mapper.
The override only took keyword arguments, so fsspec's positional check,
create and missing_exceptions raised TypeError.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was no way to name a path in the home directory in a URL.
ssh://host/~/filebecame/~/file, a directory named~at the root (#55).A leading
~element now means the home directory, in URLs and in paths alike._strip_protocolturns it into., which SFTP servers resolve to the home directory:ssh://host/~/data/file./data/file~/data/file./data/filessh://host/~,~.(the home directory)~/~/file(a directory named~)./~/filessh://host/data/file/data/file(unchanged)/~/file(a plain path, such as one fromls("/"))/~/file(unchanged: a directory named~at the root)~data,data/~/filemakedirsand uploads treat.like"": it always exists, so it's never created.fs.get_mapper("")roots the mapper at., so a key named~is a file there too. Results keep the./prefix:ls("~")returns./a.txt, soglob("~/*")matches every entry, and a~element after the prefix stays a file named~when the path is stripped again, asrmdoes. Listings of""(#106) name a file called~./~, sofind("")doesn't recurse into the home directory through it.This follows curl, which treats
sftp://host/~/fileas home-relative and other URL paths as absolute, and the expired IETF draft forsftp://URIs, which uses the same~element. fsspec's local filesystem also expands~in paths. OpenSSH'ssftpandscpresolve every URL path against the home directory (absolute paths need//). Switching to that would change where existing URLs likessh://host/data/filepoint, so URL paths stay absolute, and the class docstring now says so.The branch includes #106's commit, so merge #106 first. Checked against OpenSSH 10.0:
cat_file,ls,info,glob,find,makedirs,pipe_fileandrmwork with~paths, andrm("~/~/a.txt")removes only the file inside the~directory. The new tests fail onmain.Fixes #55.
🤖 Generated with Claude Code