Installer: add check for file existence & fix path resolving (#1397)

This commit is contained in:
David Sevilla Martín 2018-08-19 17:40:37 -04:00 committed by Franz Liedke
parent 195f77ff10
commit ca16a23383

View File

@ -23,12 +23,37 @@ class WritablePaths extends AbstractPrerequisite
public function check()
{
foreach ($this->paths as $path) {
if (! is_writable($path)) {
if (! file_exists($path)) {
$this->errors[] = [
'message' => 'The '.realpath($path).' directory is not writable.',
'message' => 'The '.$this->getAbsolutePath($path).' directory doesn\'t exist',
'detail' => 'This directory is necessary for the installation. Please create the folder.',
];
} elseif (! is_writable($path)) {
$this->errors[] = [
'message' => 'The '.$this->getAbsolutePath($path).' directory is not writable.',
'detail' => 'Please chmod this directory'.($path !== public_path() ? ' and its contents' : '').' to 0775.'
];
}
}
}
private function getAbsolutePath($path)
{
$path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = [];
foreach ($parts as $part) {
if ('.' == $part) {
continue;
}
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return (substr($path, 0, 1) == '/' ? '/' : '').implode(DIRECTORY_SEPARATOR, $absolutes);
}
}