]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/helper/ApplicationUtils.php
Merge pull request #1695 from ArthurHoaro/fix/ut-curl
[github/shaarli/Shaarli.git] / application / helper / ApplicationUtils.php
index 212dd8e2dc7578aa6da6a3f8d403fff319ae3f42..f79998b51f54dcf68014db1c80b307d2919137df 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;
 
 /**
@@ -35,7 +37,7 @@ class ApplicationUtils
     {
         list($headers, $data) = get_http_response($url, $timeout);
 
-        if (strpos($headers[0], '200 OK') === false) {
+        if (preg_match('#HTTP/[\d\.]+ 200(?: OK)?#', $headers[0]) !== 1) {
             error_log('Failed to retrieve ' . $url);
             return false;
         }
@@ -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.
      *