From f6a00f35ae0ea8a77a77a49f8e027eb269a9ea5d Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 11 Jan 2020 01:41:19 +0200 Subject: [PATCH] ssh: fix bug in remove() --- dvc/remote/ssh/connection.py | 6 ++---- tests/unit/remote/ssh/test_connection.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dvc/remote/ssh/connection.py b/dvc/remote/ssh/connection.py index 674bfc2c3..ccfa5d736 100644 --- a/dvc/remote/ssh/connection.py +++ b/dvc/remote/ssh/connection.py @@ -156,14 +156,12 @@ class SSHConnection: 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) diff --git a/tests/unit/remote/ssh/test_connection.py b/tests/unit/remote/ssh/test_connection.py index 2b329b424..3f79d9a49 100644 --- a/tests/unit/remote/ssh/test_connection.py +++ b/tests/unit/remote/ssh/test_connection.py @@ -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"