From 77e99e0961e9b162b6e755ccdc632b8435d99a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sun, 19 Aug 2018 17:40:37 -0400 Subject: [PATCH] Installer: add check for file existence & fix path resolving (#1397) --- .../Install/Prerequisite/WritablePaths.php | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/framework/core/src/Install/Prerequisite/WritablePaths.php b/framework/core/src/Install/Prerequisite/WritablePaths.php index 311e62e92..1f356ee6a 100644 --- a/framework/core/src/Install/Prerequisite/WritablePaths.php +++ b/framework/core/src/Install/Prerequisite/WritablePaths.php @@ -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); + } }