GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — serve sftp: fix rmdir deleting a file instead of returning an error by hsdfat · Pull Request #10220 · rclone/rclone

Conversation

@hsdfat

@hsdfat hsdfat commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

What does this change do?

serve sftp handled Rmdir and Remove in the same case, calling vfs.Remove, which removes any node type. So an SSH_FXP_RMDIR sent to a regular file deleted the file. OpenSSH's sftp-server fails that with ENOTDIR, and serve ftp already guards it in DeleteDir.

Rmdir now stats the path and returns ENOTDIR if it isn't a directory, then removes it as before. pkg/sftp reports that to the client as SSH_FX_FAILURE "not a directory". Directories (including ENOTEMPTY for non-empty ones) and Remove behave as before.

TestRmdirFile runs a real server and client: rmdir on a file must fail and leave the file intact, and rmdir on an empty directory must still work. On master the file gets deleted.

Linked issue

None. Small bug fix (data loss) found while reading the handler.

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hsdfat
serve sftp: fix rmdir deleting a file instead of returning an error
0456459
An SSH_FXP_RMDIR request on a file removed the file, as rmdir and
remove were both handled by VFS.Remove. Make rmdir return ENOTDIR for
anything which isn't a directory, as serve ftp already does.
@hsdfat
hsdfat requested review from albertony and ncw as code owners October 30, 2026 23:10
agammann
agammann approved these changes Nov 1, 2026
View reviewed changes

@agammann agammann left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I reviewed the Filecmd dispatch and the VFS directory removal path. Rmdir now rejects a regular file with ENOTDIR before removal, while a directory still goes through Dir.Remove() and its empty-directory check; Remove keeps its separate behavior. I ran go test ./cmd/serve/sftp -run TestRmdirFile -count=1 on this head in a Linux Go 1.26 container, and it passed. I did not run the full SFTP suite.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ncw
ncw approved these changes Nov 5, 2026
View reviewed changes

@ncw ncw left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you, very nice fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ncw
ncw merged commit 2fb0f2c into rclone:master Nov 5, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@hsdfat
hsdfat deleted the serve-sftp-rmdir-file branch November 6, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ncw ncw ncw approved these changes
@albertony albertony Awaiting requested review from albertony albertony is a code owner
+1 more reviewer
@agammann agammann agammann approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@hsdfat @ncw @agammann
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.