From 71397f82e4bdf4722bcbfeb43be0d30831376d3d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 4 Jun 2014 14:20:36 +0200 Subject: [PATCH] Remove forced dir removal before install, fixes #3035 --- src/Composer/Downloader/FileDownloader.php | 3 +-- src/Composer/Downloader/VcsDownloader.php | 2 +- src/Composer/Util/Filesystem.php | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 709835444..fc903fd66 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -107,8 +107,7 @@ class FileDownloader implements DownloaderInterface protected function doDownload(PackageInterface $package, $path, $url) { - $this->filesystem->removeDirectory($path); - $this->filesystem->ensureDirectoryExists($path); + $this->filesystem->emptyDirectory($path); $fileName = $this->getFileName($package, $path); diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 55a12954e..b0f0b7cbc 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -55,7 +55,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa } $this->io->write(" - Installing " . $package->getName() . " (" . VersionParser::formatVersion($package) . ")"); - $this->filesystem->removeDirectory($path); + $this->filesystem->emptyDirectory($path); $urls = $package->getSourceUrls(); while ($url = array_shift($urls)) { diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index e81cacdb7..fab4c5793 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -74,7 +74,25 @@ class Filesystem { $dir = rtrim($dir, '/\\'); - return count($this->realpathGlob($dir.'/*') ?: array()) === 0 && count($this->realpathGlob($dir.'/.*') ?: array()) === 2; + return count($this->realpathGlob($dir.'/*')) === 0 && count($this->realpathGlob($dir.'/.*')) === 2; + } + + public function emptyDirectory($dir, $ensureDirectoryExists = true) + { + if ($ensureDirectoryExists) { + $this->ensureDirectoryExists($dir); + } + + if (is_dir($dir)) { + foreach ($this->realpathGlob(rtrim($dir, '\\/').'/*') as $path) { + $this->remove($path); + } + foreach ($this->realpathGlob(rtrim($dir, '\\/').'/.*') as $path) { + if (basename($path) !== '..' && basename($path) !== '.') { + $this->remove($path); + } + } + } } /**