Repository navigation
serve sftp: fix rmdir deleting a file instead of returning an error - #10220
Merged
Merged
Conversation
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.
agammann
approved these changes
Nov 1, 2026
agammann
left a comment
There was a problem hiding this comment.
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this change do?
serve sftphandledRmdirandRemovein the samecase, callingvfs.Remove, which removes any node type. So an SSH_FXP_RMDIR sent to a regular file deleted the file. OpenSSH'ssftp-serverfails that with ENOTDIR, andserve ftpalready guards it inDeleteDir.Rmdirnow stats the path and returnsENOTDIRif 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) andRemovebehave as before.TestRmdirFileruns 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
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.