Skip to content

fix: prefix paths starting with - with ./ in cp, md5sum and md5 - #92

Merged
shcheklein merged 2 commits into
mainfrom
fix/shell-commands-leading-dash
Nov 29, 2026
Merged

shcheklein merged 2 commits into
mainfrom
fix/shell-commands-leading-dash

Conversation

@shcheklein

@shcheklein shcheklein commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

cp_file and checksum quote paths for the shell, but quoting doesn't stop cp, md5sum or md5 from parsing a name that starts with -:

  • fs.cp_file("-r", "copy") runs cp -r copy, which fails with a usage error. fs.checksum("-r") fails the same way with GNU md5sum, and macOS md5 treats -r as an option.
  • fs.checksum("-") makes md5sum and md5 read stdin instead of the file. The command's stdin is never closed, so the call hangs.

This prefixes paths that start with - with ./, which fixes both cases. Passing -- wouldn't fix the second, because md5sum -- - and md5 -- - still read stdin. Only relative paths can start with -, and ./ resolves them against the same directory.

The checksum test has a timeout, so a regression fails instead of hanging the suite.

This touches the same lines as #75 and #86. Split out of #86.

🤖 Generated with Claude Code

Quoting a path for the shell doesn't stop cp, md5sum or md5 from
parsing a name that starts with "-" as an option: cp_file("-r", "copy")
ran "cp -r copy" and failed with a usage error. GNU and BSD cp and
md5sum, and macOS md5, all accept "--" to end the options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein added a commit to kushaldave002/sshfs that referenced this pull request Nov 28, 2026
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 shcheklein left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(AI-generated review by Copilot)

Clean, minimal fix for option-like leading-dash paths (-r, etc.). Inline notes on the bare "-" edge case in md5sum/md5, centralizing shell command construction with #86, and splitting/renaming the test.

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

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 were identified for the change addressing leading-dash filenames in remote copy and checksum operations.

No open issues 🎉

What changed in this PR

This PR fixes remote copy and checksum operations for relative paths beginning with -, preventing filenames from being interpreted as command options.

Changes:

  • Adds -- before path arguments passed to cp, md5sum, and md5.
  • Adds a regression test covering copy and checksum operations with leading-dash filenames.
File Description
tests/​test_sshfs.py Tests copying and checksumming a file named -r.
sshfs/​spec.py Separates command options from path arguments with --.

Review effort: Balanced

md5sum and md5 read stdin for a "-" argument even after "--", so
checksum("-") hung, because the command's stdin is never closed. A "./"
prefix keeps both "-" and option-like names such as "-r" from being
parsed by cp, md5sum and md5.

The test is split into a cp_file test and a checksum test, each next
to its existing test. The checksum test covers "-" and has a timeout,
so a regression fails instead of hanging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shcheklein shcheklein changed the title fix: pass -- before paths in cp, md5sum and md5 fix: prefix paths starting with - with ./ in cp, md5sum and md5 Nov 29, 2026
@shcheklein
shcheklein requested a balanced review from Copilot November 29, 2026 01:16

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 leading-dash path handling change.

No open issues 🎉

Review effort: Balanced

@shcheklein
shcheklein merged commit 04923a2 into main Nov 29, 2026
11 checks passed
shcheklein added a commit to kushaldave002/sshfs that referenced this pull request Nov 29, 2026
Resolves the conflicts with fsspec#91 and fsspec#92. The tests from both sides are
kept, and _quote, which now builds bytes, gets the "./" prefix from fsspec#92
for paths that start with "-".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shcheklein
shcheklein deleted the fix/shell-commands-leading-dash branch November 29, 2026 03:04
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.

2 participants