mirror of
https://github.com/flarum/framework.git
synced 2025-02-20 23:24:55 +08:00
Installer: add check for file existence & fix path resolving (#1397)
This commit is contained in:
parent
195f77ff10
commit
ca16a23383
@ -23,12 +23,37 @@ class WritablePaths extends AbstractPrerequisite
|
|||||||
public function check()
|
public function check()
|
||||||
{
|
{
|
||||||
foreach ($this->paths as $path) {
|
foreach ($this->paths as $path) {
|
||||||
if (! is_writable($path)) {
|
if (! file_exists($path)) {
|
||||||
$this->errors[] = [
|
$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.'
|
'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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user