]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/helper/ApplicationUtils.php
Fix: soft fail if the mutex is not working
[github/shaarli/Shaarli.git] / application / helper / ApplicationUtils.php
index 212dd8e2dc7578aa6da6a3f8d403fff319ae3f42..a6c03aaeae899daebb46bb37884dc3422694b6d0 100644 (file)
@@ -3,6 +3,8 @@
 namespace Shaarli\Helper;
 
 use Exception;
+use malkusch\lock\exception\LockAcquireException;
+use malkusch\lock\mutex\FlockMutex;
 use Shaarli\Config\ConfigManager;
 
 /**
@@ -252,6 +254,20 @@ class ApplicationUtils
         return $errors;
     }
 
+    public static function checkDatastoreMutex(): array
+    {
+        $mutex = new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2);
+        try {
+            $mutex->synchronized(function () {
+                return true;
+            });
+        } catch (LockAcquireException $e) {
+            $errors[] = t('Lock can not be acquired on the datastore. You might encounter concurrent access issues.');
+        }
+
+        return $errors ?? [];
+    }
+
     /**
      * Returns a salted hash representing the current Shaarli version.
      *