From 57fe33d0f371a95232d74e64c5c559eeac77a24f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 11 Mar 2013 14:02:49 +0100 Subject: [PATCH] Make sure the directory is empty even if weird inputs are given, fixes #1683 --- src/Composer/Installer/ProjectInstaller.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Composer/Installer/ProjectInstaller.php b/src/Composer/Installer/ProjectInstaller.php index 29bb7d126..5d98722c8 100644 --- a/src/Composer/Installer/ProjectInstaller.php +++ b/src/Composer/Installer/ProjectInstaller.php @@ -29,7 +29,7 @@ class ProjectInstaller implements InstallerInterface public function __construct($installPath, DownloadManager $dm) { - $this->installPath = $installPath; + $this->installPath = rtrim(strtr($installPath, '\\', '/'), '/').'/'; $this->downloadManager = $dm; } @@ -58,14 +58,11 @@ class ProjectInstaller implements InstallerInterface public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { $installPath = $this->installPath; - if (file_exists($installPath) && (count(glob($installPath.'/*')) || count(glob($installPath.'/.*')) > 2)) { - throw new \InvalidArgumentException("Project directory $installPath already exists."); - } - if (!file_exists(dirname($installPath))) { - throw new \InvalidArgumentException("Project root " . dirname($installPath) . " does not exist."); + if (file_exists($installPath) && (count(glob($installPath.'*')) || (count(glob($installPath.'.*')) > 2))) { + throw new \InvalidArgumentException("Project directory $installPath is not empty."); } if (!is_dir($installPath)) { - mkdir($installPath, 0777); + mkdir($installPath, 0777, true); } $this->downloadManager->download($package, $installPath); }