Skip to content

Commit

Permalink
FtpServer, SshServer: purge() checkes if directory exists [Closes #126]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 7, 2019
1 parent e59e688 commit 4526b88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Deployment/FtpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==
Expand Down
7 changes: 5 additions & 2 deletions src/Deployment/SshServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4526b88

Please sign in to comment.