MDL-43390 files: Only lock when locking is not prevented

This commit is contained in:
David Monllao 2014-07-14 12:13:41 +08:00
parent 5fd0df97c5
commit 10ccdfb8cd

View File

@ -1721,6 +1721,8 @@ class file_storage {
* @return array (contenthash, filesize, newfile)
*/
public function add_string_to_pool($content) {
global $CFG;
$contenthash = sha1($content);
$filesize = strlen($content); // binary length
@ -1755,7 +1757,13 @@ class file_storage {
// Hopefully this works around most potential race conditions.
$prev = ignore_user_abort(true);
$newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX);
if (!empty($CFG->preventfilelocking)) {
$newsize = file_put_contents($hashfile.'.tmp', $content);
} else {
$newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX);
}
if ($newsize === false) {
// Borked permissions most likely.
ignore_user_abort($prev);