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 6314026 commit fabf692
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions datalad_ria/patches/sshremoteio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 fabf692

Please sign in to comment.