From 4526b8887537e323cfcbfd45a87a64f411e1b1ab Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 7 May 2019 17:50:05 +0200 Subject: [PATCH] FtpServer, SshServer: purge() checkes if directory exists [Closes #126] --- src/Deployment/FtpServer.php | 4 ++++ src/Deployment/SshServer.php | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Deployment/FtpServer.php b/src/Deployment/FtpServer.php index 13b11d86..42d33653 100644 --- a/src/Deployment/FtpServer.php +++ b/src/Deployment/FtpServer.php @@ -209,6 +209,10 @@ public function removeDir(string $dir): void */ public function purge(string $dir, callable $progress = null): void { + if (!$this->isDir($dir)) { + return; + } + $dirs = []; foreach ((array) Safe::ftp_nlist($this->connection, $dir) as $entry) { if ($entry == null || $entry === $dir || preg_match('#(^|/)\\.+$#', $entry)) { // intentionally == diff --git a/src/Deployment/SshServer.php b/src/Deployment/SshServer.php index 70124062..874fc5eb 100644 --- a/src/Deployment/SshServer.php +++ b/src/Deployment/SshServer.php @@ -175,9 +175,12 @@ public function removeDir(string $dir): void */ public function purge(string $dir, callable $progress = null): void { - $dirs = $entries = []; + if (!file_exists($path = 'ssh2.sftp://' . (int) $this->sftp . $dir)) { + return; + } - $iterator = Safe::dir($path = 'ssh2.sftp://' . (int) $this->sftp . $dir); + $dirs = $entries = []; + $iterator = Safe::dir($path); while (($entry = $iterator->read()) !== false) { if ($entry !== '.' && $entry !== '..') { $entries[] = $entry;