MDL-25500 Lock: Do not use file locking if $CFG->preventfilelocking is set

(And file_lock_dir is not prefixed with the dataroot).
This commit is contained in:
Damyon Wiese 2014-01-28 20:14:05 +08:00
parent 9843e5ece5
commit d551112566
2 changed files with 12 additions and 10 deletions

View 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;
}
/**

View 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;