diff --git a/datalad_ria/patches/sshremoteio.py b/datalad_ria/patches/sshremoteio.py index 0f235f3f..0be12781 100644 --- a/datalad_ria/patches/sshremoteio.py +++ b/datalad_ria/patches/sshremoteio.py @@ -182,9 +182,22 @@ def _strip_endmarker_newline(lines): return "".join(lines) +# The method 'SSHRemoteIO_run' is a patched version of +# 'datalad/distributed/ora-remote.py:SSHRemoteIO._run' +# from datalad@58b8e06317fe1a03290aed80526bff1e2d5b7797 +def SSHRemoteIO_remove_dir(self, path): + with self.ensure_writeable(path.parent): + self._run('rmdir {}'.format(sh_quote(str(path))), + # THIS IS THE PATCH + # we want it to fail, like rmdir() would fail + # on non-empty dirs + check=True) + + for target, patch in ( ('__init__', SSHRemoteIO__init__), ('_append_end_markers', SSHRemoteIO_append_end_markers), ('_run', SSHRemoteIO_run), + ('remove_dir', SSHRemoteIO_remove_dir), ): apply_patch('datalad.distributed.ora_remote', 'SSHRemoteIO', target, patch) diff --git a/datalad_ria/tests/test_ssh_remote_io.py b/datalad_ria/tests/test_ssh_remote_io.py index b87fc3a6..d86af4fa 100644 --- a/datalad_ria/tests/test_ssh_remote_io.py +++ b/datalad_ria/tests/test_ssh_remote_io.py @@ -1,7 +1,10 @@ from pathlib import PurePosixPath import pytest -from datalad.distributed.ora_remote import SSHRemoteIO +from datalad.distributed.ora_remote import ( + RemoteCommandFailedError, + SSHRemoteIO, +) @pytest.fixture(autouse=False, scope="function") @@ -65,8 +68,8 @@ def test_SSHRemoteIO_handledir(ssh_remoteio, ria_sshserver_setup): ssh_remoteio.write_file(targetfpath, 'dummy') assert ssh_remoteio.exists(targetfpath) - # XXX calling remove_dir()has no effect, and causes no error!!! - ssh_remoteio.remove_dir(targetdir) + with pytest.raises(RemoteCommandFailedError): + ssh_remoteio.remove_dir(targetdir) assert ssh_remoteio.exists(targetdir) # we must "know" that there is content and remove it