MDL-25500 Lock: Do not use file locking if $CFG->preventfilelocking is set
authorDamyon Wiese <damyon@moodle.com>
Tue, 28 Jan 2014 12:14:05 +0000 (20:14 +0800)
committerDamyon Wiese <damyon@moodle.com>
Tue, 28 Jan 2014 12:14:05 +0000 (20:14 +0800)
(And file_lock_dir is not prefixed with the dataroot).

lib/classes/lock/file_lock_factory.php
lib/classes/lock/lock_config.php

index 17c084a..5257427 100644 (file)
@@ -94,10 +94,15 @@ class file_lock_factory implements lock_factory {
 
     /**
      * Is available.
-     * @return boolean - True if this lock type is available in this environment.
+     * @return boolean - True if preventfilelocking is not set - or the file_lock_root is not in dataroot.
      */
     public function is_available() {
-        return true;
+        $preventfilelocking = !empty($CFG->preventfilelocking);
+        $lockdirisdataroot = true;
+        if (!empty($CFG->file_lock_root) && strpos($CFG->file_lock_root, $CFG->dataroot) !== 0) {
+            $lockdirisdataroot = false;
+        }
+        return !$preventfilelocking || !$lockdirisdataroot;
     }
 
     /**
index 50d2e18..d1212bc 100644 (file)
@@ -61,16 +61,13 @@ class lock_config {
             // DB Specific lock factory is prefered - should support auto-release.
             $lockfactoryclass = "\\core\\lock\\${dbtype}_lock_factory";
             if (!class_exists($lockfactoryclass)) {
-                if (empty($CFG->preventfilelocking)) {
-                    // File locking is second option - if $CFG->preventfilelocking allows it.
-                    $lockfactoryclass = '\core\lock\file_lock_factory';
-                } else {
-                    // Final fallback - DB row locking. Does not support auto-release - so on failures
-                    // we will have to wait for a timeout.
-                    $lockfactoryclass = '\core\lock\db_record_lock_factory';
-                }
+                $lockfactoryclass = '\core\lock\file_lock_factory';
             }
             $lockfactory = new $lockfactoryclass($type);
+            if (!$lockfactory->is_available()) {
+                // Final fallback - DB row locking.
+                $lockfactory = new \core\lock\db_record_lock_factory($type);
+            }
         }
 
         return $lockfactory;