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

Commit 8674f70

Browse files
committed
feature #176 Check if the installer has enough permissions *before* downloading the file (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #176). Discussion ---------- Check if the installer has enough permissions *before* downloading the file This fixes #175 Commits ------- 478b09e Check if the installer has enough permissions *before* downloading the file
2 parents dde530f + 478b09e commit 8674f70

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Symfony/Installer/DemoCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
try {
6363
$this
6464
->checkProjectName()
65+
->checkPermissions()
6566
->download()
6667
->extract()
6768
->cleanUp()

src/Symfony/Installer/DownloadCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Helper\ProgressBar;
2525
use Symfony\Component\Console\Input\InputInterface;
2626
use Symfony\Component\Console\Output\OutputInterface;
27+
use Symfony\Component\Filesystem\Exception\IOException;
2728
use Symfony\Component\Filesystem\Filesystem;
2829
use Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException;
2930
use Symfony\Installer\Exception\AbortException;
@@ -299,6 +300,20 @@ protected function createGitIgnore()
299300
return $this;
300301
}
301302

303+
/**
304+
* Checks if the installer has enough permissions to create the project.
305+
*/
306+
protected function checkPermissions()
307+
{
308+
$projectParentDirectory = dirname($this->projectDir);
309+
310+
if (!is_writable($projectParentDirectory)) {
311+
throw new IOException(sprintf('Installer does not have enough permissions to write to the "%s" directory.', $projectParentDirectory));
312+
}
313+
314+
return $this;
315+
}
316+
302317
/**
303318
* Utility method to show the number of bytes in a readable format.
304319
*
@@ -334,7 +349,7 @@ protected function getErrorMessage(\Requirement $requirement, $lineSize = 70)
334349
return;
335350
}
336351

337-
$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
352+
$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
338353
$errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
339354

340355
return $errorMessage;

src/Symfony/Installer/NewCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5454
$this
5555
->checkProjectName()
5656
->checkSymfonyVersionIsInstallable()
57+
->checkPermissions()
5758
->download()
5859
->extract()
5960
->cleanUp()

0 commit comments

Comments
 (0)