Skip to content

Commit

Permalink
ssh: fix bug in remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jan 11, 2020
1 parent 8154c89 commit f6a00f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions dvc/remote/ssh/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,12 @@ def _remove_file(self, path):
def _remove_dir(self, path):
for root, dirs, files in self.walk(path, topdown=False):
for fname in files:
path = posixpath.join(root, fname)
with suppress(FileNotFoundError):
self._remove_file(path)
self._remove_file(posixpath.join(root, fname))

for dname in dirs:
path = posixpath.join(root, dname)
with suppress(FileNotFoundError):
self.sftp.rmdir(dname)
self.sftp.rmdir(posixpath.join(root, dname))

with suppress(FileNotFoundError):
self.sftp.rmdir(path)
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/remote/ssh/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def test_makedirs(tmp_path, ssh):
assert os.path.isdir(path)


def test_remove_dir(tmp_path, ssh):
dpath = tmp_path / "dir"
dpath.mkdir()
(dpath / "file").write_text("file")
(dpath / "subdir").mkdir()
(dpath / "subdir" / "subfile").write_text("subfile")
ssh.remove(dpath.absolute().as_posix())
assert not dpath.exists()


def test_walk(tmp_path, ssh):
root_path = tmp_path
dir_path = root_path / "dir"
Expand Down

0 comments on commit f6a00f3

Please sign in to comment.