From da2f19b88f34fea11ecd599d0a5ca1b26a4ab100 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 25 Apr 2022 02:30:15 +0800 Subject: [PATCH] change lock file at ROOT_PATH --- nexus/Install/Install.php | 14 ++++++++++---- nexus/Install/Update.php | 2 ++ nexus/Install/install/install.php | 3 +-- nexus/Install/update/update.php | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index 2d2e84d5..e38ac239 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -37,11 +37,14 @@ class Install ['name' => 'swoole', 'desc' => "If use swoole for Octane, make sure 'current' shows 1"], ]; + protected string $lockFile = 'install.lock'; + public function __construct() { if (!session_id()) { session_start(); } + $this->checkLock(); $this->currentStep = min(intval($_REQUEST['step'] ?? 1) ?: 1, count($this->steps) + 1); } @@ -639,16 +642,19 @@ class Install return compact('version', 'match'); } - public function checkLock($path) + public function checkLock() { - if (file_exists("$path/.lock")) { + $fullFilename = ROOT_PATH . $this->lockFile; + if (file_exists($fullFilename)) { die("Locked! Delete .lock file first"); } } - public function setLock($path) + public function setLock() { - file_put_contents("$path/.lock", "Lock at: " . date('Y-m-d H:i:s')); + $fullFilename = ROOT_PATH . $this->lockFile; + $res = file_put_contents($fullFilename, "Lock at: " . date('Y-m-d H:i:s')); + $this->doLog("set lock at: $fullFilename, result: " . var_export($res, true)); } } diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 429a4f4c..3ec88817 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -29,6 +29,8 @@ class Update extends Install protected $steps = ['Env check', 'Get files', 'Update .env', 'Perform updates']; + protected string $lockFile = 'update.lock'; + public function getLogFile() { diff --git a/nexus/Install/install/install.php b/nexus/Install/install/install.php index 55e2d53a..608d5a9d 100644 --- a/nexus/Install/install/install.php +++ b/nexus/Install/install/install.php @@ -5,7 +5,6 @@ require ROOT_PATH . 'nexus/Install/install_update_start.php'; $isPost = $_SERVER['REQUEST_METHOD'] == 'POST'; $install = new \Nexus\Install\Install(); -$install->checkLock(__DIR__); $currentStep = $install->currentStep(); $maxStep = $install->maxStep(); if (!$install->canAccessStep($currentStep)) { @@ -192,7 +191,7 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) { echo '
For questions, consult the installation log at: ' . $install->getLogFile() . '
'; echo '
For security reasons, please delete the following directories
'; echo '
' . $install->getInsallDirectory() . '
'; - $install->setLock(__DIR__); + $install->setLock(); } echo''; diff --git a/nexus/Install/update/update.php b/nexus/Install/update/update.php index 13b70798..c249d1d2 100644 --- a/nexus/Install/update/update.php +++ b/nexus/Install/update/update.php @@ -5,7 +5,6 @@ require ROOT_PATH . 'nexus/Install/install_update_start.php'; $isPost = $_SERVER['REQUEST_METHOD'] == 'POST'; $update = new \Nexus\Install\Update(); -$update->checkLock(__DIR__); $currentStep = $update->currentStep(); $maxStep = $update->maxStep(); if (!$update->canAccessStep($currentStep)) { @@ -230,7 +229,7 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) { echo '
For questions, consult the upgrade log at: ' . $update->getLogFile() . '
'; echo '
For security reasons, please delete the following directories
'; echo '
' . $update->getUpdateDirectory() . '
'; - $update->setLock(__DIR__); + $update->setLock(); } echo'';