Skip to content

Commit

Permalink
SSHRemoteIO.remove_dir() now fails on non-empty directories
Browse files Browse the repository at this point in the history
This aligns its behavior with `FileIO.remove_dir()`.

Closes #82
  • Loading branch information
mih committed Sep 21, 2023
1 parent 0f3c711 commit cee36f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 17 additions & 0 deletions datalad_ria/patches/sshremoteio.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
by prefixing the marker itself with a newline (which is withheld form the
actual output).
4. ``SSHRemoteIO.remove_dir()`` would not fail (unlike ``FileIO.remove_dir()``)
when ran on a non-empty directory. Despite not failing, it would also not
remove that directory.
In addition, this patch modifies two comments. It adds a missing description of
the ``buffer_size``-parameter of ``SSHRemoteIO.__init__``to the doc-string, and
fixes the description of the condition in the comment on the use of
Expand Down Expand Up @@ -182,9 +186,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)
9 changes: 6 additions & 3 deletions datalad_ria/tests/test_ssh_remote_io.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cee36f8

Please sign in to comment.