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

Allow to install Symfony when the directory exists but it's empty #99

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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.'/'));
}
}