From 5987114f6ce0c26e4adb825c7156bf7367464f4e Mon Sep 17 00:00:00 2001 From: polarathene Date: Tue, 5 Nov 2019 20:29:57 +1300 Subject: [PATCH] Fix: Fail when install location is a file In the event a file has the same name as the intended install directory, fail fast too. --- src/Composer/Command/CreateProjectCommand.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 7a43eb990..9fc9ea0d7 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -286,8 +286,12 @@ EOT } $fs = new Filesystem(); - if (is_dir($directory) && !$fs->isDirEmpty($directory)) { - throw new \InvalidArgumentException("Project directory $directory is not empty."); + if (file_exists($directory)) { + if (!is_dir($directory)) { + throw new \InvalidArgumentException('Cannot create project directory at "'.$directory.'", it exists as a file.'); + } elseif (!$fs->isDirEmpty($directory)) { + throw new \InvalidArgumentException('Project directory "'.$directory.'" is not empty.'); + } } if (null === $stability) {