aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/helper
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-11-24 13:28:17 +0100
committerArthurHoaro <arthur@hoa.ro>2020-11-24 13:39:35 +0100
commit8a6b7e96b7176e03238bbb1bcaa4c8b0c25e6358 (patch)
treeb0e8910856393fe11a022faf32969915de9f598f /application/helper
parente4b8330e459b598328bf250208386c06ec257b08 (diff)
downloadShaarli-8a6b7e96b7176e03238bbb1bcaa4c8b0c25e6358.tar.gz
Shaarli-8a6b7e96b7176e03238bbb1bcaa4c8b0c25e6358.tar.zst
Shaarli-8a6b7e96b7176e03238bbb1bcaa4c8b0c25e6358.zip
Fix: soft fail if the mutex is not working
And display the error in server admin page Fixes #1650
Diffstat (limited to 'application/helper')
-rw-r--r--application/helper/ApplicationUtils.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/application/helper/ApplicationUtils.php b/application/helper/ApplicationUtils.php
index 212dd8e2..a6c03aae 100644
--- a/application/helper/ApplicationUtils.php
+++ b/application/helper/ApplicationUtils.php
@@ -3,6 +3,8 @@
3namespace Shaarli\Helper; 3namespace Shaarli\Helper;
4 4
5use Exception; 5use Exception;
6use malkusch\lock\exception\LockAcquireException;
7use malkusch\lock\mutex\FlockMutex;
6use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
7 9
8/** 10/**
@@ -252,6 +254,20 @@ class ApplicationUtils
252 return $errors; 254 return $errors;
253 } 255 }
254 256
257 public static function checkDatastoreMutex(): array
258 {
259 $mutex = new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2);
260 try {
261 $mutex->synchronized(function () {
262 return true;
263 });
264 } catch (LockAcquireException $e) {
265 $errors[] = t('Lock can not be acquired on the datastore. You might encounter concurrent access issues.');
266 }
267
268 return $errors ?? [];
269 }
270
255 /** 271 /**
256 * Returns a salted hash representing the current Shaarli version. 272 * Returns a salted hash representing the current Shaarli version.
257 * 273 *