ssh: fix bug in remove()

This commit is contained in:
Ruslan Kuprieiev
2020-01-11 03:14:45 +02:00
parent 8154c89c3f
commit f6a00f35ae
2 changed files with 12 additions and 4 deletions
+2 -4
View File
@@ -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)
+10
View File
@@ -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"