From 4d825fa6a698645dc588bde6ef5339e534b5f31c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 25 Feb 2023 19:30:41 +0300 Subject: [PATCH] require PHP to have support for flock() --- classes/config.php | 4 ++++ include/functions.php | 19 ++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/classes/config.php b/classes/config.php index 9a8b466ab..a865266ca 100644 --- a/classes/config.php +++ b/classes/config.php @@ -541,6 +541,10 @@ class Config { array_push($errors, "PHP support for JSON is required, but was not found."); } + if (!function_exists("flock")) { + array_push($errors, "PHP support for flock() function is required."); + } + if (!class_exists("PDO")) { array_push($errors, "PHP support for PDO is required but was not found."); } diff --git a/include/functions.php b/include/functions.php index 0d7f8c756..5096e9c65 100644 --- a/include/functions.php +++ b/include/functions.php @@ -366,21 +366,18 @@ function file_is_locked(string $filename): bool { if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$filename")) { - if (function_exists('flock')) { - $fp = @fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "r"); - if ($fp) { - if (flock($fp, LOCK_EX | LOCK_NB)) { - flock($fp, LOCK_UN); - fclose($fp); - return false; - } + $fp = @fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "r"); + if ($fp) { + if (flock($fp, LOCK_EX | LOCK_NB)) { + flock($fp, LOCK_UN); fclose($fp); - return true; - } else { return false; } + fclose($fp); + return true; + } else { + return false; } - return true; // consider the file always locked and skip the test } else { return false; }