diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index c8e8b14..3e698f7 100755 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ private function checkProjectName() { - if (is_dir($this->projectDir)) { + if (is_dir($this->projectDir) && !$this->isEmptyDirectory($this->projectDir)) { throw new \RuntimeException(sprintf( "There is already a '%s' project in this directory (%s).\n". "Change your project name or create it in another directory.", @@ -609,4 +609,17 @@ private function getExecutedCommand() return sprintf('%s new %s %s', $executedCommand, $this->projectName, $version); } + + /** + * Checks whether the given directory is empty or not. + * + * @param string $dir the path of the directory to check + * @return bool + */ + private function isEmptyDirectory($dir) + { + // glob() cannot be used because it doesn't take into account hidden files + // scandir() returns '.' and '..' for an empty dir + return 2 === count(scandir($dir.'/')); + } }