From c8a8662875d0dbedb3474b1d7496015b4a79f1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A7=98=E7=9A=84man?= <2755488504@qq.com> Date: Thu, 19 Nov 2026 00:44:44 +0800 Subject: [PATCH] fix: synchronous `rmdir()` fails silently OSS-Contributor-Artifact: 679ddc0a35296cf762b24d17c4b87bdaba100df8da492fcf82efcb739ccd2836 --- sshfs/spec.py | 2 ++ tests/test_oss_regression_38.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/test_oss_regression_38.py diff --git a/sshfs/spec.py b/sshfs/spec.py index 2338040..b3da1fe 100644 --- a/sshfs/spec.py +++ b/sshfs/spec.py @@ -351,6 +351,8 @@ async def _rmdir( else: await channel.rmdir(path) + rmdir = sync_wrapper(_rmdir) + async def _rm(self, path, recursive=False, **kwargs): path = self._strip_protocol(path) if isinstance(path, (str, bytes)): diff --git a/tests/test_oss_regression_38.py b/tests/test_oss_regression_38.py new file mode 100644 index 0000000..6f6a18f --- /dev/null +++ b/tests/test_oss_regression_38.py @@ -0,0 +1,19 @@ +import pytest +from test_sshfs import fs, plain_remote_dir, remote_dir, ssh_server + + +def test_rmdir_removes_directory(fs, remote_dir): + path = remote_dir + "/empty" + fs.mkdir(path) + assert fs.isdir(path) + + fs.rmdir(path) + assert not fs.exists(path) + + with pytest.raises(FileNotFoundError): + fs.rmdir(path) + + fs.makedirs(path + "/child") + fs.touch(path + "/child/file") + fs.rmdir(path, recursive=True) + assert not fs.exists(path)