Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 07e93d9

Browse files
committed
feature #99 Allow to install Symfony when the directory exists but it's empty (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #99). Discussion ---------- Allow to install Symfony when the directory exists but it's empty This fixes #98 Commits ------- a8499ef Allow to install Symfony when the directory exists but it's empty
2 parents 13d7a97 + a8499ef commit 07e93d9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9797
*/
9898
private function checkProjectName()
9999
{
100-
if (is_dir($this->projectDir)) {
100+
if (is_dir($this->projectDir) && !$this->isEmptyDirectory($this->projectDir)) {
101101
throw new \RuntimeException(sprintf(
102102
"There is already a '%s' project in this directory (%s).\n".
103103
"Change your project name or create it in another directory.",
@@ -609,4 +609,17 @@ private function getExecutedCommand()
609609

610610
return sprintf('%s new %s %s', $executedCommand, $this->projectName, $version);
611611
}
612+
613+
/**
614+
* Checks whether the given directory is empty or not.
615+
*
616+
* @param string $dir the path of the directory to check
617+
* @return bool
618+
*/
619+
private function isEmptyDirectory($dir)
620+
{
621+
// glob() cannot be used because it doesn't take into account hidden files
622+
// scandir() returns '.' and '..' for an empty dir
623+
return 2 === count(scandir($dir.'/'));
624+
}
612625
}

0 commit comments

Comments
 (0)