Skip to content

Commit

Permalink
Merge pull request #52 from Akkes1/feature/deletion-fallback-logic
Browse files Browse the repository at this point in the history
[FtpClient] Retry deletion by renaming the path
  • Loading branch information
Nicolab authored Jan 6, 2021
2 parents 85b6434 + e7d4168 commit 3c34d6b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/FtpClient/FtpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,19 @@ public function remove($path, $recursive = false)

try {
if (@$this->ftp->delete($path)
or ($this->isDir($path) and $this->rmdir($path, $recursive))) {
or ($this->isDir($path)
and $this->rmdir($path, $recursive))) {
return true;
} else {
// in special cases the delete can fail (for example, at Symfony's "r+e.gex[c]a(r)s" directory)
$newPath = preg_replace('/[^A-Za-z0-9\/]/', '', $path);
if ($this->rename($path, $newPath)) {
if (@$this->ftp->delete($newPath)
or ($this->isDir($newPath)
and $this->rmdir($newPath, $recursive))) {
return true;
}
}
}

return false;
Expand Down

0 comments on commit 3c34d6b

Please sign in to comment.